<?php
	require_once APPPATH . 'controllers/base_controllers/base_controller.php';

	class Member_reports extends Base_controller
	{
		public static $REGISTRATION_TEMPLATE = 'templates/registration/registration_template';		
		
		
		public function __construct()
		{
			parent::__construct();
			
			$this->load->model('values/cwr_registrant_member_homepage_value');
			$this->load->model('values/person_value');
			$this->load->model('values/member_info_value');
            $this->load->model('values/mahasamadhi/mahasamadhi_registration_value');
		}
		
		public function download_management_dashboard_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			//$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$curyear = $this->Walk_proxy->getCurrentYear();			
			
			if (in_array("admin",$role) or in_array("superadmin",$role) or in_array("board",$group))
			{
				$dashinfoarr = $this->Reports_proxy->getManagementDashboardData($curyear);
				
				$uniqueKey = $this->encrypt->get_random_password(10,10,false,true,false);
				
				$filePath = "reports";
                $curdatetime = time();  
                $filedate = date('Y-m-d', $curdatetime);
				$fileName = "balavihar_dashboard_".$curyear."_".$filedate.".csv";
			
				$fp=fopen($filePath."/".$fileName,'a');
				
				$curdate = date('m/d/Y', $curdatetime);
				fwrite($fp, "Date:,".$curdate."\n");
				$curtime = date('h:i:s A', $curdatetime);
				fwrite($fp, "Time:,".$curtime."\n");
				fwrite($fp, "Year:,".$curyear.'-'.($curyear+1)."\n");
					
				fwrite($fp, "Center,Session,Prev Grade,Curr Grade,#Prev,#Curr,#Common,#Drop Out,%Drop Out,#New,%Attendance\n");
				
				foreach( $dashinfoarr as $dashrec)
				{
					if ($dashrec[4] > 0)
						$percentdo = floor(100.0*$dashrec[7]/$dashrec[4]);
					else
						$percentdo = 0;
					
					if ($dashrec[10] > 0)
						$percentatt = floor(100.0*$dashrec[9]/$dashrec[10]);
					else
						$percentatt = 0;
						
					fwrite($fp, $dashrec[0].",".$dashrec[1].",".$dashrec[2].",".$dashrec[3].",".$dashrec[4].",".$dashrec[5].",".$dashrec[6].",".$dashrec[7].",".$percentdo.",".$dashrec[8].",".$percentatt."\n");
				}				 

				fclose($fp);  // close file
				
				$this->Reports_proxy->download_file( $filePath, $fileName );
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
		}

		public function download_members_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			//$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$curyear = $this->Walk_proxy->getCurrentYear();			
			
			if (in_array("admin",$role) or in_array("superadmin",$role) or in_array("board",$group))
			{
				$searchcriteria = $this->session->userdata( 'searchcriteria');
	
				$reginfo = $this->Reports_proxy->getMembers($searchcriteria);
				
				$uniqueKey = $this->encrypt->get_random_password(10,10,false,true,false);
				
				$filePath = "reports";
                $curdatetime = time();  
                $filedate = date('Y-m-d', $curdatetime);
				$fileName = "members_".$fileName.".csv";
			
				$fp=fopen($filePath."/".$fileName,'a');
				
				$curdate = date('m/d/Y', $curdatetime);
				fwrite($fp, "Date:,".$curdate."\n");
				$curtime = date('h:i:s A', $curdatetime);
				fwrite($fp, "Time:,".$curtime."\n");

				//---Search criteria----
				fwrite($fp, "Search Criteria:\n");
				
				if (!empty($searchcriteria['memberlastname']))
					fwrite($fp, "Member Last Name:,".$searchcriteria['memberlastname']."\n");
				else
					fwrite($fp, "Member Last Name:,All\n");
				
				if (!empty($searchcriteria['memberfirstname']))
					fwrite($fp, "Member First Name:,".$searchcriteria['memberfirstname']."\n");
				else
					fwrite($fp, "Member First Name:,All\n");

				if (!empty($searchcriteria['membercity']))
					fwrite($fp, "Member City:,".$searchcriteria['membercity']."\n");
				else
					fwrite($fp, "Member City:,All\n");

				if (!empty($searchcriteria['memberstate']))
					fwrite($fp, "Member State:,".$searchcriteria['memberstate']."\n");
				else
					fwrite($fp, "Member State:,All\n");

				if (!empty($searchcriteria['centername']))
					fwrite($fp, "Member Center:,".$searchcriteria['centername']."\n");
				else
					fwrite($fp, "Member Center:,All\n");
				//----------------------

				fwrite($fp, "Number of search results: ".count($reginfo)."\n\n");
					
				fwrite($fp, "First Name,Last Name,City,State,Zip,Center\n");
				
				foreach( $reginfo as $regrec)
				{
					fwrite($fp, "\"".$regrec['firstname']."\",\"".$regrec['lastname']."\",\"".$regrec['city']."\",\"".$regrec['state']."\",\"".$regrec['zip']."\",\"".$regrec['center_name']."\"\n");
				}				 

				fclose($fp);  // close file
				
				$this->session->unset_userdata( 'searchcriteria');
				
				$this->Reports_proxy->download_file( $filePath, $fileName );
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
		}

		public function download_registered_households_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			//$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$curyear = $this->Walk_proxy->getCurrentYear();			
			
			if (in_array("admin",$role) or in_array("superadmin",$role) or in_array("board",$group))
			{
				$searchcriteria = $this->session->userdata( 'searchcriteria');
	
				$reginfo = $this->Reports_proxy->getRegisteredMembersAdmin($curyear, $searchcriteria);
				
				$uniqueKey = $this->encrypt->get_random_password(10,10,false,true,false);
				
				$filePath = "reports";
				$fileName = "registered_households_".$uniqueKey.".csv";
			
				$fp=fopen($filePath."/".$fileName,'a');
				
				$curdatetime = time();	
				$curdate = date('m/d/Y', $curdatetime);
				fwrite($fp, "\""."Date: ".$curdate."\"\n");
				$curtime = date('h:i:s A', $curdatetime);
				fwrite($fp, "Time: ".$curtime."\n");

				//---Search criteria----
				fwrite($fp, "Search Criteria:\n");
				
				if (!empty($searchcriteria['memberlastname']))
					fwrite($fp, "Member Last Name: ".$searchcriteria['memberlastname']."\n");
				else
					fwrite($fp, "Member Last Name: All\n");
				
				if (!empty($searchcriteria['memberfirstname']))
					fwrite($fp, "Member First Name: ".$searchcriteria['memberfirstname']."\n");
				else
					fwrite($fp, "Member First Name: All\n");

				if (!empty($searchcriteria['membercity']))
					fwrite($fp, "Member City: ".$searchcriteria['membercity']."\n");
				else
					fwrite($fp, "Member City: All\n");

				if (!empty($searchcriteria['memberstate']))
					fwrite($fp, "Member State: ".$searchcriteria['memberstate']."\n");
				else
					fwrite($fp, "Member State: All\n");

				if (!empty($searchcriteria['centername']))
					fwrite($fp, "Member Center: ".$searchcriteria['centername']."\n");
				else
					fwrite($fp, "Member Center: All\n");

				if (!empty($searchcriteria['memtype']))
					fwrite($fp, "Member Type: ".$searchcriteria['memtype']."\n");
				else
					fwrite($fp, "Member Type: All\n");

				if (!empty($searchcriteria['paytype']))
					fwrite($fp, "Member Payment Type: ".$searchcriteria['paytype']."\n");
				else
					fwrite($fp, "Member Payment Type: All\n");

				if (!empty($searchcriteria['paid']))
					fwrite($fp, "Member Payment Status: ".$searchcriteria['paid']."\n");
				else
					fwrite($fp, "Member Payment Status: All\n");
				//----------------------

				fwrite($fp, "Number of search results: ".count($reginfo)."\n\n");
					
				fwrite($fp, "First Name,Last Name,Phone,Email,Address,City,State,Zip,Center,Member Type,Session,Amount Committed,Payment Type,Payment Status\n");
				
				foreach( $reginfo as $regrec)
				{
					fwrite($fp, "\"".$regrec['firstname']."\",\"".$regrec['lastname']."\",\"".$regrec['phone']."\",\"".$regrec['email']."\",\"".$regrec['address']."\",\"".$regrec['city']."\",\"".$regrec['state']."\",\"".$regrec['zip']."\",\"".$regrec['center_name']."\",\"".$regrec['type']."\",\"".$regrec['session']."\",\"".$regrec['amount_paid']."\",\"".$regrec['payment_type']."\",\"".$regrec['fully_paid']."\"\n");
				}				 

				fclose($fp);  // close file
				
				$this->session->unset_userdata( 'searchcriteria');
				
				$this->Reports_proxy->download_file( $filePath, $fileName );
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
		}

		public function download_registered_households_list_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			//$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$curyear = $this->Walk_proxy->getCurrentYear();			
			
			if (in_array("admin",$role) or in_array("superadmin",$role) or in_array("board",$group))
			{
				//Get all registered members in alphabetical order by last name
				$hhidarr = $this->Reports_proxy->getRegisteredHouseholdsAdmin( $curyear );
				
				//Get registered households info
				$householdinfo = $this->Reports_proxy->getHouseholdInfoAdmin( $hhidarr, $curyear );
				
				$uniqueKey = $this->encrypt->get_random_password(10,10,false,true,false);
				
				$filePath = "reports";
				$fileName = "registered_households_list_".$uniqueKey.".csv";
			
				$fp=fopen($filePath."/".$fileName,'a');
				
				$curdatetime = time();	
				$curdate = date('m/d/Y', $curdatetime);
				fwrite($fp, "\""."Date: ".$curdate."\"\n");
				$curtime = date('h:i:s A', $curdatetime);
				fwrite($fp, "Time: ".$curtime."\n");

				foreach($householdinfo as $hharr)
				{
					foreach( $hharr as $hhrec)
					{
						switch($hhrec[2])
						{
							case 'Primary':
								fwrite($fp,"\"".strval($hhrec[0])."\"\n");
								fwrite($fp,"\"".strval($hhrec[17])."\"\n");
								for( $i = 2; $i < 13; $i++ )
								{
									fwrite($fp,"\"".strval($hhrec[$i])."\"\n");
								}
								break;							
							case 'Spouse':
								for( $i = 2; $i < 9; $i++ )
								{
									fwrite($fp,"\"".strval($hhrec[$i])."\"\n");
								}
								break;
							case 'Child':
								for( $i = 2; $i < 6; $i++ )
								{
									fwrite($fp,"\"".strval($hhrec[$i])."\"\n");
								}
								fwrite($fp,"\"".strval($hhrec[13])."\"\n");
								fwrite($fp,"\"".strval($hhrec[14])."\"\n");
								break;
						}
					}
												
					fwrite($fp,"----------------------------------------------------\n");
				}
				fclose($fp);  // close file
				
				$this->session->unset_userdata( 'searchcriteria');
				
				$this->Reports_proxy->download_file( $filePath, $fileName );
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
		}

		public function download_registered_tickets_list_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			//$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$curyear = $this->Walk_proxy->getCurrentYear();			
			
			if (in_array("admin",$role) or in_array("superadmin",$role) or in_array("board",$group))
			{
				//Get all registered members in alphabetical order by last name
				$hhidarr = $this->Reports_proxy->getRegisteredHouseholdsAdmin( $curyear );
				
				//Get registered households info
				$householdinfo = $this->Reports_proxy->getHouseholdInfoAdmin( $hhidarr, $curyear );
				
				$uniqueKey = $this->encrypt->get_random_password(10,10,false,true,false);
				
				$filePath = "reports";
				$fileName = "registered_tickets_list_".$uniqueKey.".csv";
			
				$fp=fopen($filePath."/".$fileName,'a');
				
				$curdatetime = time();	
				$curdate = date('m/d/Y', $curdatetime);
				fwrite($fp, "\""."Date: ".$curdate."\"\n");
				$curtime = date('h:i:s A', $curdatetime);
				fwrite($fp, "Time: ".$curtime."\n");

				foreach($householdinfo as $hharr)
				{
					foreach( $hharr as $hhrec)
					{
						switch($hhrec[2])
						{
							case 'Primary':
								if ($hhrec[17] == "Paid")
									fwrite($fp,"\"CONFIRMED\"\n");
								else
								{
									if ($hhrec[17] == "Unpaid")
										fwrite($fp,"\"UNPAID\"\n");
									else
										fwrite($fp,"\"WAITING FOR CHECK\"\n");;
								}
								fwrite($fp,"\"".$hhrec[0]."\"\n");
								fwrite($fp,"\"".$hhrec[5]."\"\n");
								fwrite($fp,"\"".$hhrec[3]."\"\n");							
								break;							
							case 'Spouse':
								fwrite($fp,"\"".$hhrec[3]."\"\n");
								break;
							case 'Child':
								fwrite($fp,"\"".$hhrec[3]."\",\"".$hhrec[14]."\",\"".$hhrec[18]."\",\"".$hhrec[19]."\"\n");
								break;
						}
					}
												
					fwrite($fp,"----------------------------------------------------\n");
				}
				fclose($fp);  // close file
				
				$this->session->unset_userdata( 'searchcriteria');
				
				$this->Reports_proxy->download_file( $filePath, $fileName );
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
		}

		public function download_unregistered_households_list_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			//$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$curyear = $this->Walk_proxy->getCurrentYear();			
			
			if (in_array("admin",$role) or in_array("superadmin",$role) or in_array("board",$group))
			{
				//Get all unregistered members in alphabetical order by last name
				$hhidarr = $this->Reports_proxy->getUnregisteredHouseholdsAdmin( $curyear );
				
				//Get unregistered households info
				$householdinfo = $this->Reports_proxy->getHouseholdInfoAdmin( $hhidarr, ($curyear-1) );
				
				$uniqueKey = $this->encrypt->get_random_password(10,10,false,true,false);
				
				$filePath = "reports";
				$fileName = "unregistered_households_list_".$uniqueKey.".csv";
			
				$fp=fopen($filePath."/".$fileName,'a');
				
				$curdatetime = time();	
				$curdate = date('m/d/Y', $curdatetime);
				fwrite($fp, "\""."Date: ".$curdate."\"\n");
				$curtime = date('h:i:s A', $curdatetime);
				fwrite($fp, "Time: ".$curtime."\n");

				foreach($householdinfo as $hharr)
				{
					foreach( $hharr as $hhrec)
					{
						switch($hhrec[2])
						{
							case 'Primary':
								fwrite($fp,"\"".strval($hhrec[0])."\"\n");
								for( $i = 2; $i < 13; $i++ )
								{
									fwrite($fp,"\"".strval($hhrec[$i])."\"\n");
								}
								break;							
							case 'Spouse':
								for( $i = 2; $i < 9; $i++ )
								{
									fwrite($fp,"\"".strval($hhrec[$i])."\"\n");
								}
								break;
							case 'Child':
								for( $i = 2; $i < 6; $i++ )
								{
									fwrite($fp,"\"".strval($hhrec[$i])."\"\n");
								}
								fwrite($fp,"\"".strval($hhrec[13])."\"\n");
								fwrite($fp,"\"".strval($hhrec[14])."\"\n");
								break;
						}
					}
												
					fwrite($fp,"----------------------------------------------------\n");
				}
				fclose($fp);  // close file
				
				$this->session->unset_userdata( 'searchcriteria');
				
				$this->Reports_proxy->download_file( $filePath, $fileName );
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
		}

		public function download_unregistered_tickets_list_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			//$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$curyear = $this->Walk_proxy->getCurrentYear();			
			
			if (in_array("admin",$role) or in_array("superadmin",$role) or in_array("board",$group))
			{
				//Get all unregistered members in alphabetical order by last name
				$hhidarr = $this->Reports_proxy->getUnregisteredHouseholdsAdmin( $curyear );
				
				//Get unregistered households info
				$householdinfo = $this->Reports_proxy->getHouseholdInfoAdmin( $hhidarr, ($curyear-1) );
				
				$uniqueKey = $this->encrypt->get_random_password(10,10,false,true,false);
				
				$filePath = "reports";
				$fileName = "unregistered_tickets_list_".$uniqueKey.".csv";
			
				$fp=fopen($filePath."/".$fileName,'a');
				
				$curdatetime = time();	
				$curdate = date('m/d/Y', $curdatetime);
				fwrite($fp, "\""."Date: ".$curdate."\"\n");
				$curtime = date('h:i:s A', $curdatetime);
				fwrite($fp, "Time: ".$curtime."\n");

				foreach($householdinfo as $hharr)
				{
					foreach( $hharr as $hhrec)
					{
						switch($hhrec[2])
						{
							case 'Primary':
								fwrite($fp,"\"UNREGISTERED\"\n");
								fwrite($fp,"\"".$hhrec[0]."\"\n");
								fwrite($fp,"\"".$hhrec[5]."\"\n");
								fwrite($fp,"\"".$hhrec[3]."\"\n");							
								break;							
							case 'Spouse':
								fwrite($fp,"\"".$hhrec[3]."\"\n");
								break;
							case 'Child':
								fwrite($fp,"\"".$hhrec[3]."\",\"".$hhrec[14]."\",\"".$hhrec[18]."\",\"".$hhrec[19]."\"\n");
								break;
						}
					}
												
					fwrite($fp,"----------------------------------------------------\n");
				}
				fclose($fp);  // close file
				
				$this->session->unset_userdata( 'searchcriteria');
				
				$this->Reports_proxy->download_file( $filePath, $fileName );
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
		}

		public function download_balavihar_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			//$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$curyear = $this->Walk_proxy->getCurrentYear();			
			
			if (in_array("admin",$role) or in_array("superadmin",$role) or in_array("board",$group))
			{
				$searchcriteria = $this->session->userdata( 'searchcriteria');
				$specifiedyear = $searchcriteria['specifiedyear'];
	
				$bvinfo = $this->Reports_proxy->getBalaviharAdminData($specifiedyear, $searchcriteria);
				
				$uniqueKey = $this->encrypt->get_random_password(10,10,false,true,false);
				
				$filePath = "reports";
                $curdatetime = time();  
                $filedate = date('Y-m-d', $curdatetime);
				$fileName = "balavihar_classes_".$filedate.".csv";
			
				$fp=fopen($filePath."/".$fileName,'a');
				
				$curdate = date('m/d/Y', $curdatetime);
				fwrite($fp, "Date:,".$curdate."\n");
				$curtime = date('h:i:s A', $curdatetime);
				fwrite($fp, "Time:,".$curtime."\n");
				fwrite($fp, "Year:,".$specifiedyear.'-'.($specifiedyear+1)."\n");

				//---Search criteria----
				fwrite($fp, "Search Criteria:\n");
				
				if (!empty($searchcriteria['memberlastname']))
					fwrite($fp, "Student Last Name:,".$searchcriteria['memberlastname']."\n");
				else
					fwrite($fp, "Student Last Name:,All\n");
				
				if (!empty($searchcriteria['memberfirstname']))
					fwrite($fp, "Student First Name:,".$searchcriteria['memberfirstname']."\n");
				else
					fwrite($fp, "Student First Name:,All\n");

				if (!empty($searchcriteria['membercity']))
					fwrite($fp, "Student City:,".$searchcriteria['membercity']."\n");
				else
					fwrite($fp, "Student City: All\n");
				if (!empty($searchcriteria['memberstate']))
					fwrite($fp, "Student State:,".$searchcriteria['memberstate']."\n");
				else
					fwrite($fp, "Student State:,All\n");

				if (!empty($searchcriteria['centername']))
					fwrite($fp, "Student Center:,".$searchcriteria['centername']."\n");
				else
					fwrite($fp, "Student Center:,All\n");

				if (!empty($searchcriteria['session']))
					fwrite($fp, "Student Session:,".$searchcriteria['session']."\n");
				else
					fwrite($fp, "Student Session:,All\n");

				if (!empty($searchcriteria['gradename']))
					fwrite($fp, "Student Grade:,".$searchcriteria['gradename']."\n");
				else
					fwrite($fp, "Student Grade:,All\n");
				//----------------------

				fwrite($fp, "#Total:,".count($bvinfo)."\n\n");
					
				fwrite($fp, "First Name,Last Name,Grade,Session,Center,City,State\n");
				
				foreach( $bvinfo as $bvrec)
				{
					fwrite($fp, $bvrec['firstname'].",".$bvrec['lastname'].",".$bvrec['gradename'].",".$bvrec['session'].",".$bvrec['centername'].",".$bvrec['city'].",".$bvrec['state']."\n");
				}				 

				fclose($fp);  // close file
				
				$this->session->unset_userdata( 'searchcriteria');
				
				$this->Reports_proxy->download_file( $filePath, $fileName );
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
		}

        public function download_balavihar_all_class_assignment_report( $urlKey )
        {
            $this->load->model('proxies/Person_proxy');
            $this->load->model('proxies/Walk_proxy');
            $this->load->model('proxies/Reports_proxy');
            $this->load->library('encrypt');
            
            $is_logged_in = $this->session->userdata( 'is_logged_in' );
            if (!$is_logged_in)
            {
                redirect( base_url() . 'cmb/member/login_home/' );
            }

            $seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
            if ($seckey != $this->session->userdata( 'logged_in_key' ))
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $personId = $this->session->userdata( 'person_id' );
            if ( $personId < 1 )
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $group = $this->Person_proxy->getPersonGroup( $personId );
            $role = $this->Person_proxy->getPersonRole( $personId );

            $curyear = $this->Walk_proxy->getCurrentYear();         
            
            if (in_array("admin",$role) or in_array("superadmin",$role) or in_array("board",$group) or in_array("balavihar",$group))
            {
                $searchcriteria = $this->session->userdata( 'searchcriteria');
                $status = $searchcriteria['status'];
                
                $bvinfoall = array();
                    
                $centername = "Andover";
                $session = "AM";
                $gradename = "Pre-K";
                $bvinfo = $this->Reports_proxy->getBalaviharSpecificClassAssignmentData( $curyear, $centername, $session, $gradename, $status );
                foreach( $bvinfo as $bvrec)
                {
                    array_push($bvinfoall, $bvrec);
                }

                    
                $gradename = "K";
                $bvinfo = $this->Reports_proxy->getBalaviharSpecificClassAssignmentData( $curyear, $centername, $session, $gradename , $status);
                foreach( $bvinfo as $bvrec)
                {
                    array_push($bvinfoall, $bvrec);
                }

                for($k=1; $k<13; $k++)
                {
                    $gradename = strval($k);
                    $bvinfo = $this->Reports_proxy->getBalaviharSpecificClassAssignmentData( $curyear, $centername, $session, $gradename, $status );
                    foreach( $bvinfo as $bvrec)
                    {
                        array_push($bvinfoall, $bvrec);
                    }                    
                }

                $centername = "Andover";
                $session = "PM";
                $gradename = "Pre-K";
                $bvinfo = $this->Reports_proxy->getBalaviharSpecificClassAssignmentData( $curyear, $centername, $session, $gradename, $status );
                foreach( $bvinfo as $bvrec)
                {
                    array_push($bvinfoall, $bvrec);
                }

                    
                $gradename = "K";
                $bvinfo = $this->Reports_proxy->getBalaviharSpecificClassAssignmentData( $curyear, $centername, $session, $gradename, $status );
                foreach( $bvinfo as $bvrec)
                {
                    array_push($bvinfoall, $bvrec);
                }

                for($k=1; $k<10; $k++)
                {
                    $gradename = strval($k);
                    $bvinfo = $this->Reports_proxy->getBalaviharSpecificClassAssignmentData( $curyear, $centername, $session, $gradename, $status );
                    foreach( $bvinfo as $bvrec)
                    {
                        array_push($bvinfoall, $bvrec);
                    }                    
                }

                $centername = "Andover";
                $session = "PM2";
                $gradename = "Pre-K";
                $bvinfo = $this->Reports_proxy->getBalaviharSpecificClassAssignmentData( $curyear, $centername, $session, $gradename, $status );
                foreach( $bvinfo as $bvrec)
                {
                    array_push($bvinfoall, $bvrec);
                }

                    
                $gradename = "K";
                $bvinfo = $this->Reports_proxy->getBalaviharSpecificClassAssignmentData( $curyear, $centername, $session, $gradename, $status );
                foreach( $bvinfo as $bvrec)
                {
                    array_push($bvinfoall, $bvrec);
                }

                for($k=1; $k<9; $k++)
                {
                    $gradename = strval($k);
                    $bvinfo = $this->Reports_proxy->getBalaviharSpecificClassAssignmentData( $curyear, $centername, $session, $gradename, $status );
                    foreach( $bvinfo as $bvrec)
                    {
                        array_push($bvinfoall, $bvrec);
                    }                    
                }

                $centername = "MetroWest";
                $session = "PM";
                $gradename = "Pre-K";
                $bvinfo = $this->Reports_proxy->getBalaviharSpecificClassAssignmentData( $curyear, $centername, $session, $gradename, $status );
                foreach( $bvinfo as $bvrec)
                {
                    array_push($bvinfoall, $bvrec);
                }

                    
                $gradename = "K";
                $bvinfo = $this->Reports_proxy->getBalaviharSpecificClassAssignmentData( $curyear, $centername, $session, $gradename, $status );
                foreach( $bvinfo as $bvrec)
                {
                    array_push($bvinfoall, $bvrec);
                }

                for($k=1; $k<13; $k++)
                {
                    $gradename = strval($k);
                    $bvinfo = $this->Reports_proxy->getBalaviharSpecificClassAssignmentData( $curyear, $centername, $session, $gradename, $status );
                    foreach( $bvinfo as $bvrec)
                    {
                        array_push($bvinfoall, $bvrec);
                    }                    
                }
                
                $uniqueKey = $this->encrypt->get_random_password(10,10,false,true,false);
                
                $filePath = "reports";
                $curdatetime = time();  
                $filedate = date('Y-m-d_His', $curdatetime);
                //$fileName = "balavihar__".$uniqueKey.".csv";
                $fileName = "balavihar_all_class_assignment_report_".$filedate.".csv";
            
                $fp=fopen($filePath."/".$fileName,'a');
                
                $curdate = date('m/d/Y', $curdatetime);
                fwrite($fp, "Date:,".$curdate."\n");
                $curtime = date('h:i:s A', $curdatetime);
                fwrite($fp, "Time:,".$curtime."\n");
                fwrite($fp, "Year:,".$curyear.'-'.($curyear+1)."\n");
                
                $numreg = 0;
                $numunreg = 0;
                $numtot = 0;
                if (count($bvinfoall) > 0)
                {
                    foreach( $bvinfoall as $bvrec)
                    {
                        if ($bvrec['fully_paid'] == "Unregistered")
                            $numunreg ++;
                        else 
                            $numreg ++;
                    }
                    
                    $numtot = $numreg  + $numunreg;                
                }

                fwrite($fp, "#Reg:,".$numreg."\n");
                fwrite($fp, "#Unreg:,".$numunreg."\n");
                    
                fwrite($fp, "\nSeq#,HH_ID,Center,Session,Grade,Language,First Name,Last Name,DOB,City,State,Parent Name,Phone#,Parent Email,Child Email,Pay Status\n");
                
                $i = 1;
                foreach( $bvinfoall as $bvrec)
                {
                    fwrite($fp, $i.",".$bvrec['household_id'].",".$bvrec['centername'].",".$bvrec['session'].",".$bvrec['gradename'].",".$bvrec['language'].",".$bvrec['firstname'].",".$bvrec['lastname'].",".$bvrec['birth_date'].",".$bvrec['city'].",".$bvrec['state'].",".$bvrec['parent_name'].",".$bvrec['parent_phone'].",".$bvrec['parent_email'].",".$bvrec['child_email'].",".$bvrec['fully_paid']."\n");
                    
                    $i++;
                }                

                fclose($fp);  // close file
                
                $this->Reports_proxy->download_file( $filePath, $fileName );
            }
            else
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
        }

		public function download_balavihar_class_assignment_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$curyear = $this->Walk_proxy->getCurrentYear();			
			
			if (in_array("admin",$role) or in_array("superadmin",$role) or in_array("board",$group) or in_array("balavihar",$group))
			{
				$searchcriteria = $this->session->userdata( 'searchcriteria');
	
				$bvinfo = $this->Reports_proxy->getBalaviharClassAssignmentData($curyear, $searchcriteria);
				
				$uniqueKey = $this->encrypt->get_random_password(10,10,false,true,false);
				
				$filePath = "reports";
                $curdatetime = time();  
				$filedate = date('Y-m-d', $curdatetime);
				//$fileName = "balavihar__".$uniqueKey.".csv";
				$fileName = "balavihar_class_assignment_report_".$searchcriteria['centername']."_".$searchcriteria['session']."_".$searchcriteria['gradename']."_".$filedate.".csv";
			
				$fp=fopen($filePath."/".$fileName,'a');
				
				$curdate = date('m/d/Y', $curdatetime);
				fwrite($fp, "Date:,".$curdate."\n");
				$curtime = date('h:i:s A', $curdatetime);
				fwrite($fp, "Time:,".$curtime."\n");
				fwrite($fp, "Year:,".$curyear.'-'.($curyear+1)."\n");
				
				$numreg = 0;
                $numunreg = 0;
                $numtot = 0;
				if (count($bvinfo) > 0)
				{
					fwrite($fp, "Center:,".$searchcriteria['centername']."\n");
					fwrite($fp, "Session:,".$searchcriteria['session']."\n");
					fwrite($fp, "Grade:,".$searchcriteria['gradename']."\n");

                    foreach( $bvinfo as $bvrec)
                    {
                        if ($bvrec['fully_paid'] == "Unregistered")
                            $numunreg ++;
                        else 
                            $numreg ++;
                    }
                    
                    $numtot = $numreg  + $numunreg;                
				}
				else
				{
					fwrite($fp, "Center:,n/a\n");
					fwrite($fp, "Session:,n/a\n");
					fwrite($fp, "Grade:,n/a\n");					
				}

                fwrite($fp, "#Reg:,".$numreg."\n");
                fwrite($fp, "#Unreg:, ".$numunreg."\n");
				fwrite($fp, "#Total:,".$numtot."\n");
					
				$bvrec = $bvinfo[0];
				$teachers = $this->Reports_proxy->getTeachersFromGroup( $bvrec['teacher_group_id'] );
				
				if (count($bvinfo) > 0)
				{
					$i = 1;
					foreach ($teachers as $tvrec)
					{
						fwrite($fp, "Teacher".$i.":,".$tvrec."\n");						
						$i ++;						
					}
				}
				else
				{
					fwrite($fp, "Teacher".$i.":\n");			
				}

				fwrite($fp, "\nSeq#,HH_ID,First Name,Last Name,DOB,City,State,Parent Name,Phone#,Parent Email,Child Email,Pay Status\n");
				
				$i = 1;
				foreach( $bvinfo as $bvrec)
				{
					fwrite($fp, $i.",".$bvrec['household_id'].",".$bvrec['firstname'].",".$bvrec['lastname'].",".$bvrec['birth_date'].",".$bvrec['city'].",".$bvrec['state'].",".$bvrec['parent_name'].",".$bvrec['parent_phone'].",".$bvrec['parent_email'].",".$bvrec['child_email'].",".$bvrec['fully_paid']."\n");
					
					$i++;
				}				 

				fclose($fp);  // close file
				
				$this->session->unset_userdata( 'searchcriteria');
				
				$this->Reports_proxy->download_file( $filePath, $fileName );
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
		}

		public function download_balavihar_class_attendance_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$curyear = $this->Walk_proxy->getCurrentYear();			
			
			if (in_array("admin",$role) or in_array("superadmin",$role) or in_array("board",$group) or in_array("balavihar",$group))
			{
				$searchcriteria = $this->session->userdata( 'searchcriteria');
				$outputformat = $this->session->userdata( 'outputformat');
				$specmonth = $this->session->userdata( 'month');
	
				$tmparr = $this->Walk_proxy->getBalaviharWeek($curyear);
				$curweekseq = $tmparr[1];
				$bvattinfo = $this->Reports_proxy->getBalaviharClassAttendanceData($curyear, $searchcriteria);
				$numweeks = count($bvattinfo);
				$numstudents = 	count($bvattinfo[0]);			
							
				$uniqueKey = $this->encrypt->get_random_password(10,10,false,true,false);
				
				$filePath = "reports";
                $curdatetime = time();  
                $filedate = date('Y-m-d', $curdatetime);
				//$fileName = "balavihar_class_attendance_".$uniqueKey.".csv";
				$fileName = "balavihar_class_attendance_".$searchcriteria['centername']."_".$searchcriteria['session']."_".$searchcriteria['gradename']."_".$filedate.".csv";
			
				$fp=fopen($filePath."/".$fileName,'a');
				
				$curdate = date('m/d/Y', $curdatetime);
				fwrite($fp, "Date:,\"".$curdate."\"\n");
				$curtime = date('h:i:s A', $curdatetime);
				fwrite($fp, "Time:,".$curtime."\n");
				fwrite($fp, "Year:,".$curyear.'-'.($curyear+1)."\n");
				
				if ($numweeks > 0)
				{
					fwrite($fp, "Center:,".$searchcriteria['centername']."\n");
					fwrite($fp, "Session:,".$searchcriteria['session']."\n");
					fwrite($fp, "Grade:,".$searchcriteria['gradename']."\n");
				}
				fwrite($fp, "#Total:,".$numstudents."\n");
					
				$bvwkrec = $bvattinfo[0];
				$bvclass = $bvwkrec[0];
				$teachers = $this->Reports_proxy->getTeachersFromGroup( $bvclass[5] );
				$i = 1;
				foreach ($teachers as $tvrec)
				{
					fwrite($fp, "Teacher:".$i.",".$tvrec."\n");					
					$i ++;						
				}
				
				if (($numweeks > 0) and ($numstudents>0))
				{
					switch (intval($outputformat))
					{
						//Output monthly
						case 1:
							$lastmonth = "";
							$iw = 0;

							if ($specmonth != "all")
							{
								$flg = true;
								do
								{
									$bvwkrec = $bvattinfo[$iw];
									$bvclass = $bvwkrec[0];
									$month = date("M",strtotime($bvclass[1]));
									$iw ++;
									if ($specmonth == strtolower($month)) $flg = false;
								} while (($iw < $numweeks) && $flg);
								$iw_beg = $iw - 1;
								
								do
								{
									$bvwkrec = $bvattinfo[$iw];
									$bvclass = $bvwkrec[0];
									$month = date("M",strtotime($bvclass[1]));
									$iw ++;
								} while (($iw < $numweeks) && ($specmonth == strtolower($month)));
								$iw_end = $iw - 1;
											
								$bvwkrec = $bvattinfo[$iw_beg];
								$bvclass = $bvwkrec[0];
								$month = date("M",strtotime($bvclass[1]));
								$year = date("Y",strtotime($bvclass[1]));
								//fwrite($fp, $month."-".$year."\n");
								fwrite($fp, "Student Name");
								
								for($i = $iw_beg; $i < $iw_end; $i++)
								{
									$bvwkrec = $bvattinfo[$i];
									$bvclass = $bvwkrec[0];
									fwrite($fp, ",".$bvclass[1]);
								}
								fwrite($fp, "\n");
			
								for($ic = 0; $ic < $numstudents; $ic++)
								{
									$bvwkrec = $bvattinfo[0];
									$bvclass = $bvwkrec[$ic];
									fwrite($fp, $bvclass[2]." ".$bvclass[3]);
													
									for($i = $iw_beg; $i < $iw_end; $i++)
									{
										$bvwkrec = $bvattinfo[$i];
										$bvclass = $bvwkrec[$ic];
										if ($bvclass[4] == 0)
											$status = "-";
										else				
										{
											if ($bvclass[4] == 1)
												$status = "+";
											else
												$status = "";
										}
											
										if ($i <= ($curweekseq-1))
											fwrite($fp, ",".$status);
										else
											fwrite($fp, ",");
									} //for($i = $iw_beg; $iw < $iw_end; $i++)
									
									fwrite($fp, "\n");
								} //for($ic = 0; $ic < $numstudents; $ic++)
							}
							else
							{
								while ($iw < $numweeks)
								{
									$bvwkrec = $bvattinfo[$iw];
									$bvclass = $bvwkrec[0];
									$month = date("M",strtotime($bvclass[1]));
									$year = date("Y",strtotime($bvclass[1]));
									
									if ($month != $lastmonth)
									{
										$iw_beg = $iw;
										$lastmonth = $month;
										fwrite($fp, $month."-".$year."\n");
										fwrite($fp, "Student Name");
										do
										{
											fwrite($fp, ",".$bvclass[1]);
											$iw ++;
											if ($iw < $numweeks)
											{
												$bvwkrec = $bvattinfo[$iw];
												$bvclass = $bvwkrec[0];
												$month = date("M",strtotime($bvclass[1]));
											}
										} while (($month == $lastmonth) && ($iw < $numweeks));
										fwrite($fp, "\n");			
									}
									
									$iw_end = $iw;
									
									for($ic = 0; $ic < $numstudents; $ic++)
									{
										$bvwkrec = $bvattinfo[0];
										$bvclass = $bvwkrec[$ic];
										fwrite($fp, $bvclass[2]." ".$bvclass[3]);
														
										for($i = $iw_beg; $i < $iw_end; $i++)
										{
											$bvwkrec = $bvattinfo[$i];
											$bvclass = $bvwkrec[$ic];
											if ($bvclass[4] == 0)
												$status = "-";
											else				
											{
												if ($bvclass[4] == 1)
													$status = "+";
												else
													$status = "na";
											}
												
											if ($i <= ($curweekseq-1))
												fwrite($fp, ",".$status);
											else
												fwrite($fp, ",");
										} //for($i = $iw_beg; $iw < $iw_end; $i++)
										
										fwrite($fp, "\n");
									} //for($ic = 0; $ic < $numstudents; $ic++)
								} //while ($iw < $numweeks)
							} //if (($numweeks > 0) and ($numstudents>0))
							break;
						//Output in blocks of 8
						case 2:
							$wkbeg = 0;
							$wk_block = 13;
							if ($specmonth != "all")
							{
								$iw = 0;
								$flg = true;
								do
								{
									$bvwkrec = $bvattinfo[$iw];
									$bvclass = $bvwkrec[0];
									$month = date("M",strtotime($bvclass[1]));
									$iw ++;
									if ($specmonth == strtolower($month)) $flg = false;
								} while (($iw < $numweeks) && $flg);
								$wkbeg = $iw - 1;
							}
							$actweeks = $numweeks - $wkbeg;
							if (($actweeks % $wk_block) != 0)
								$max_block = intval($actweeks / $wk_block) + 1;
							else
								$max_block = intval($actweeks / $wk_block);
							
							$max_week = $wkbeg + $wk_block;
								 	
							$tmparr = $this->Walk_proxy->getBalaviharWeek($curyear);
							$curweekseq = $tmparr[1];
		
							$bvwkrec = $bvattinfo[0];
							$bvclass = $bvwkrec[0];
							$teachers = $this->Reports_proxy->getTeachersFromGroup( $bvclass[5] );
		
							for($ib = 0; $ib < $max_block; $ib++)
							{
								//Write header
								fwrite($fp,"\nStudent Name");				
								for($iw = $wkbeg; $iw < $max_week; $iw++)
								{
									$bvwkrec = $bvattinfo[$iw];
									$bvclass = $bvwkrec[0];
									fwrite($fp,",".$bvclass[1]);
								}			
					
								for($ic = 0; $ic < $numstudents; $ic++)
								{
									$bvwkrec = $bvattinfo[0];
									$bvclass = $bvwkrec[$ic];
									fwrite($fp,"\n".$bvclass[2]." ".$bvclass[3]);
									
									for($iw = $wkbeg; $iw < $max_week; $iw++)
									{
										$bvwkrec = $bvattinfo[$iw];
										$bvclass = $bvwkrec[$ic];
										if ($bvclass[4] == 0)
											$status = "-";
										else				
										{
											if ($bvclass[4] == 1)
												$status = "+";
											else
												$status = "";
										}
											
										if ($iw <= ($curweekseq-1))
											fwrite($fp,",".$status);
										else
											fwrite($fp,",");
									}
								}
								
								$wkbeg += $wk_block;
								$max_week = ($wkbeg+$wk_block);
								if ($max_week > $numweeks) $max_week = $numweeks;
								fwrite($fp,"\n");
							}
							break;
						//Output all
						case 3:
							$wkbeg = 0;
							if ($specmonth != "all")
							{
								$iw = 0;
								$flg = true;
								do
								{
									$bvwkrec = $bvattinfo[$iw];
									$bvclass = $bvwkrec[0];
									$month = date("M",strtotime($bvclass[1]));
									$iw ++;
									if ($specmonth == strtolower($month)) $flg = false;
								} while (($iw < $numweeks) && $flg);
								$wkbeg = $iw - 1;
							}
							
							fwrite($fp, "Student Name");
							
							for($iw = $wkbeg; $iw < $numweeks; $iw++)
							{
								$bvwkrec = $bvattinfo[$iw];
								$bvclass = $bvwkrec[0];
								fwrite($fp, ",".$bvclass[1]);
							}			
							fwrite($fp, "\n");
					
							for($ic = 0; $ic < $numstudents; $ic++)
							{
								if ($ic % 2 != 0)
								{
									$rowColor = "#e0ffff";
								}
								else
								{
									$rowColor = "#ffffff";
								}
								
								$bvwkrec = $bvattinfo[0];
								$bvclass = $bvwkrec[$ic];
								fwrite($fp, $bvclass[2]." ".$bvclass[3]);
								
								for($iw = $wkbeg; $iw < $numweeks; $iw++)
								{
									$bvwkrec = $bvattinfo[$iw];
									$bvclass = $bvwkrec[$ic];
									if ($bvclass[4] == 0)
										$status = "-";
									else				
									{
										if ($bvclass[4] == 1)
											$status = "+";
										else
											$status = "";
									}
										
									if ($iw <= ($curweekseq-1))
									{
										fwrite($fp, ",".$status);
									}
									else
										fwrite($fp, ",");
								}
								
								fwrite($fp, "\n");
							}
							break;
					}
								
				} //if (($numweeks > 0) and ($numstudents>0))
				else
				{
					fwrite($fp, "No Results\n");			
				}
				
				fclose($fp);  // close file
				
				$this->session->unset_userdata( 'searchcriteria');
				
				$this->Reports_proxy->download_file( $filePath, $fileName );
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
		}

		public function download_balavihar_my_attendance_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );
			
			$curyear = $this->Walk_proxy->getCurrentYear();			
			
			if (in_array("admin",$role) or in_array("superadmin",$role) or in_array("board",$group) or in_array("balavihar",$group))
			{
				//Find all teacher groups associated with current login
				$teachingroups = $this->Walk_proxy->getTeacherGroups( $personId );
				if (count($teachingroups) <= 0)
				{
					echo "Member not part of any teaching group";
					die;
				}
				
				$tginfoarr = array();
				$srchinfoarr = array();
				$teachersarr = array();
	
				foreach($teachingroups as $tgid)
				{
					$searchcriteria = array();				
					$srcharr = $this->Walk_proxy->getTeacherGroupCriteria( $curyear, $tgid );
					
					$searchcriteria['centername'] = $srcharr[0];
					$searchcriteria['session'] = $srcharr[1];
					$searchcriteria['gradename'] = $srcharr[2];
	
					$bvattinfo = $this->Reports_proxy->getBalaviharClassAttendanceData($curyear, $searchcriteria);
					
					array_push($tginfoarr, $bvattinfo);
					array_push($srchinfoarr, $searchcriteria);
					
					array_push($teachersarr, $this->Reports_proxy->getTeachersFromGroup( $tgid ));
				}

				$numweeks = count($bvattinfo);
				$numteachergroups = count($tginfoarr);
				
				$numstudents = 	count($bvattinfo[0]);			
				
				$uniqueKey = $this->encrypt->get_random_password(10,10,false,true,false);
				
				$filePath = "reports";
                $curdatetime = time();  
                $filedate = date('Y-m-d', $curdatetime);
				$fileName = "balavihar_my_attendance_".$filedate.".csv";
			
				$fp=fopen($filePath."/".$fileName,'a');
				
				$curdate = date('m/d/Y', $curdatetime);
				fwrite($fp, "Date:,".$curdate."\n");
				$curtime = date('h:i:s A', $curdatetime);
				fwrite($fp, "Time:,".$curtime."\n");
				fwrite($fp, "Year:,".$curyear.'-'.($curyear+1)."\n");
				
				if (($numweeks > 0) and ($numteachergroups > 0))
				{
					$tmparr = $this->Walk_proxy->getBalaviharWeek($curyear);
					$curweekseq = $tmparr[1];
		
					for($itg = 0; $itg < $numteachergroups; $itg++)
					{
						$bvattinfo = $tginfoarr[$itg];
						$numstudents = count($bvattinfo[0]);
						$searchcriteria = $srchinfoarr[$itg];
						
						fwrite($fp, "\nCenter:,".$searchcriteria['centername']."\n");
						fwrite($fp, "Session:,".$searchcriteria['session']."\n");
						fwrite($fp, "Grade:,".$searchcriteria['gradename']."\n");
			
						fwrite($fp, "#Tot:,".$numstudents."\n");
								
						if ($numstudents > 0)
						{
							$bvwkrec = $bvattinfo[0];
							$bvclass = $bvwkrec[0];
							$teachers = $this->Reports_proxy->getTeachersFromGroup( $bvclass[5] );
		
							$i = 1;
							$teachingroups = $this->Walk_proxy->getTeacherGroups( $personId );
							foreach ($teachers as $tvrec)
							{
								fwrite($fp, "Teacher".$i.":,".$tvrec."\n");						
								$i ++;						
							}
		
							//Write header
							fwrite($fp,"Student Name");
							
							for($iw = 0; $iw < $curweekseq; $iw++)
							{
								$bvwkrec = $bvattinfo[$iw];
								$bvclass = $bvwkrec[0];
								fwrite($fp,",".$bvclass[1]);
							}			
				
							for($ic = 0; $ic < $numstudents; $ic++)
							{
								$bvwkrec = $bvattinfo[0];
								$bvclass = $bvwkrec[$ic];
								fwrite($fp,"\n".$bvclass[2]." ".$bvclass[3]);
								
								for($iw = 0; $iw < $curweekseq; $iw++)
								{
									$bvwkrec = $bvattinfo[$iw];
									$bvclass = $bvwkrec[$ic];
									if ($bvclass[4] == 0)
										$status = "-";
									else				
									{
										if ($bvclass[4] == 1)
											$status = "+";
										else
											$status = "na";
									}
										
									fwrite($fp,",".$status);
								}
							}
							
							fwrite($fp,"\n");			
						}
						else
						{
							fwrite($fp, "Teacher".$i.":\n");			
						}
					}
				}
				else
				{
					fwrite($fp, "Center:,n/a\n");
					fwrite($fp, "Session:,n/a\n");
					fwrite($fp, "Grade:,n/a\n");
				}

	
				fclose($fp);  // close file
				
				$this->Reports_proxy->download_file( $filePath, $fileName );
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
		}

		public function download_balavihar_class_roster_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			//$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$curyear = $this->Walk_proxy->getCurrentYear();			
			
			if (in_array("admin",$role) or in_array("superadmin",$role) or in_array("board",$group) or in_array("balavihar",$group))
			{
				$searchcriteria = $this->session->userdata( 'searchcriteria');
	
				//Find all teacher groups associated with current login
				$teachingroups = $this->Walk_proxy->getTeacherGroups( $personId );
                $status = "All";
				$tginfo = $this->Reports_proxy->getClassRosterData($curyear, $teachingroups, $status);
				
				$uniqueKey = $this->encrypt->get_random_password(10,10,false,true,false);
				
				$filePath = "reports";
                $curdatetime = time();  
                $filedate = date('Y-m-d', $curdatetime);
				$fileName = "balavihar_class_roster_".$filedate.".csv";
			
				$fp=fopen($filePath."/".$fileName,'a');
				
				$curdate = date('m/d/Y', $curdatetime);
				fwrite($fp, "Date:,".$curdate."\n");
				$curtime = date('h:i:s A', $curdatetime);
				fwrite($fp, "Time:,".$curtime."\n");
				fwrite($fp, "Year:,".$curyear.'-'.($curyear+1)."\n");
				fwrite($fp, "\n\n");
				
				foreach($tginfo as $bvinfo)
				{			
					$bvrec = $bvinfo[0];
					fwrite($fp, "Center:,".$bvrec['centername']."\n");
					fwrite($fp, "Session:,".$bvrec['session']."\n");
					fwrite($fp, "Grade:,".$bvrec['gradename']."\n");	
					fwrite($fp, "#Total:,".count($bvinfo)."\n");						
					
					$teachers = $this->Reports_proxy->getTeachersFromGroup( $bvrec['teacher_group_id'] );
					
					$i = 1;
					foreach ($teachers as $tvrec)
					{
						fwrite($fp, "Teacher".$i.":,".$tvrec."\n");						
						$i ++;						
					}
	
				fwrite($fp, "\nSeq#,HH_ID,First Name,Last Name,DOB,City,State,Parent Name,Phone#,Parent Email,Child Email,Pay Status\n");
				
				$i = 1;
				foreach( $bvinfo as $bvrec)
				{
					fwrite($fp, $i.",".$bvrec['household_id'].",".$bvrec['firstname'].",".$bvrec['lastname'].",".$bvrec['birth_date'].",".$bvrec['city'].",".$bvrec['state'].",".$bvrec['parent_name'].",".$bvrec['parent_phone'].",".$bvrec['parent_email'].",".$bvrec['child_email'].",".$bvrec['fully_paid']."\n");
					
					$i++;
				}				 
					
					fwrite($fp, "\n\n");
				}

				fclose($fp);  // close file
				
				$this->Reports_proxy->download_file( $filePath, $fileName );
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
		}

        public function download_balavihar_registered_class_roster_report( $urlKey )
        {
            $this->load->model('proxies/Person_proxy');
            $this->load->model('proxies/Walk_proxy');
            $this->load->model('proxies/Reports_proxy');
            $this->load->library('encrypt');
            
            $is_logged_in = $this->session->userdata( 'is_logged_in' );
            if (!$is_logged_in)
            {
                redirect( base_url() . 'cmb/member/login_home/' );
            }

            //$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );            
            $seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
            if ($seckey != $this->session->userdata( 'logged_in_key' ))
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            //$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
            $personId = $this->session->userdata( 'person_id' );
            if ( $personId < 1 )
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $group = $this->Person_proxy->getPersonGroup( $personId );
            $role = $this->Person_proxy->getPersonRole( $personId );

            $curyear = $this->Walk_proxy->getCurrentYear();         
            
            if (in_array("admin",$role) or in_array("superadmin",$role) or in_array("board",$group) or in_array("balavihar",$group))
            {
                $searchcriteria = $this->session->userdata( 'searchcriteria');
    
                //Find all teacher groups associated with current login
                $teachingroups = $this->Walk_proxy->getTeacherGroups( $personId );
                $status = "Registered";
                $tginfo = $this->Reports_proxy->getClassRosterData($curyear, $teachingroups, $status);
                
                $uniqueKey = $this->encrypt->get_random_password(10,10,false,true,false);
                
                $filePath = "reports";
                $curdatetime = time();  
                $filedate = date('Y-m-d', $curdatetime);
                $fileName = "balavihar_registered_class_roster_".$filedate.".csv";
            
                $fp=fopen($filePath."/".$fileName,'a');
                
                $curdate = date('m/d/Y', $curdatetime);
                fwrite($fp, "Date:,".$curdate."\n");
                $curtime = date('h:i:s A', $curdatetime);
                fwrite($fp, "Time:,".$curtime."\n");
                fwrite($fp, "Year:,".$curyear.'-'.($curyear+1)."\n");
                fwrite($fp, "\n\n");
                
                foreach($tginfo as $bvinfo)
                {           
                    $bvrec = $bvinfo[0];
                    fwrite($fp, "Center:,".$bvrec['centername']."\n");
                    fwrite($fp, "Session:,".$bvrec['session']."\n");
                    fwrite($fp, "Grade:,".$bvrec['gradename']."\n");    
                    fwrite($fp, "#Total:,".count($bvinfo)."\n");                        
                    
                    $teachers = $this->Reports_proxy->getTeachersFromGroup( $bvrec['teacher_group_id'] );
                    
                    $i = 1;
                    foreach ($teachers as $tvrec)
                    {
                        fwrite($fp, "Teacher".$i.":,".$tvrec."\n");                     
                        $i ++;                      
                    }
    
                fwrite($fp, "\nSeq#,HH_ID,First Name,Last Name,DOB,City,State,Parent Name,Phone#,Parent Email,Child Email,Pay Status\n");
                
                $i = 1;
                foreach( $bvinfo as $bvrec)
                {
                    fwrite($fp, $i.",".$bvrec['household_id'].",".$bvrec['firstname'].",".$bvrec['lastname'].",".$bvrec['birth_date'].",".$bvrec['city'].",".$bvrec['state'].",".$bvrec['parent_name'].",".$bvrec['parent_phone'].",".$bvrec['parent_email'].",".$bvrec['child_email'].",".$bvrec['fully_paid']."\n");
                    
                    $i++;
                }                
                    
                    fwrite($fp, "\n\n");
                }

                fclose($fp);  // close file
                
                $this->Reports_proxy->download_file( $filePath, $fileName );
            }
            else
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
        }

		public function download_language_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$curyear = $this->Walk_proxy->getCurrentYear();			
			
			if (in_array("admin",$role) or in_array("superadmin",$role) or in_array("board",$group) or in_array("balavihar",$group))
			{
				$searchcriteria = $this->session->userdata( 'searchcriteria');
	
				$langinfo = $this->Reports_proxy->getLanguageAdminData($curyear, $searchcriteria);
				
				$uniqueKey = $this->encrypt->get_random_password(10,10,false,true,false);
				
				$filePath = "reports";
                $curdatetime = time();  
                $filedate = date('Y-m-d', $curdatetime);
				$fileName = "language_classes_".$filedate.".csv";
			
				$fp=fopen($filePath."/".$fileName,'a');
				
				$curdate = date('m/d/Y', $curdatetime);
				fwrite($fp, "Date:,".$curdate."\n");
				$curtime = date('h:i:s A', $curdatetime);
				fwrite($fp, "Time:,".$curtime."\n");

				//---Search criteria----
				fwrite($fp, "Search Criteria:\n");
				
				if (!empty($searchcriteria['memberlastname']))
					fwrite($fp, "Student Last Name:,".$searchcriteria['memberlastname']."\n");
				else
					fwrite($fp, "Student Last Name:,All\n");
				
				if (!empty($searchcriteria['memberfirstname']))
					fwrite($fp, "Student First Name:,".$searchcriteria['memberfirstname']."\n");
				else
					fwrite($fp, "Student First Name:,All\n");

				if (!empty($searchcriteria['membercity']))
					fwrite($fp, "Student City:,".$searchcriteria['membercity']."\n");
				else
					fwrite($fp, "Student City:,All\n");

				if (!empty($searchcriteria['memberstate']))
					fwrite($fp, "Student State:,".$searchcriteria['memberstate']."\n");
				else
					fwrite($fp, "Student State:,All\n");

				if (!empty($searchcriteria['centername']))
					fwrite($fp, "Student Center:,".$searchcriteria['centername']."\n");
				else
					fwrite($fp, "Student Center:,All\n");

				if (!empty($searchcriteria['languagename']))
					fwrite($fp, "Student Language:,".$searchcriteria['languagename']."\n");
				else
					fwrite($fp, "Student Language:,All\n");
				//----------------------

				fwrite($fp, "#Total:,".count($langinfo)."\n\n");
					
				fwrite($fp, "\nSeq#,HH_ID,First Name,Last Name,Language,Level,Center,City,State,Parent Name,Phone#,Parent Email,Child Email,Pay Status\n");
				
				$i = 1;
				foreach( $langinfo as $langrec)
				{
					fwrite($fp, $i.",".$langrec['household_id'].",".$langrec['firstname'].",".$langrec['lastname'].",".$langrec['languagename'].",".$langrec['langlevel'].",".$langrec['centername'].",".$langrec['city'].",".$langrec['state'].",".$langrec['parent_name'].",".$langrec['parent_phone'].",".$langrec['parent_email'].",".$langrec['child_email'].",".$langrec['fully_paid']."\n");
					$i++;
				}				 

				fclose($fp);  // close file
				
				$this->session->unset_userdata( 'searchcriteria');
				
				$this->Reports_proxy->download_file( $filePath, $fileName );
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
		}

		public function download_swamivisits_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			//$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$curyear = $this->Walk_proxy->getCurrentYear();			
			
			if (($this->Person_proxy->isPersonGroupRole( $personId, "member", "admin" )) or ($this->Person_proxy->isPersonGroupRole( $personId, "member", "superadmin" )) or ($this->Person_proxy->isPersonGroupRole( $personId, "spiritual", "admin" )))
			{
				$searchcriteria = $this->session->userdata( 'searchcriteria');
	
				$svinfo = $this->Reports_proxy->getSwamivisitsAdminData($curyear, $searchcriteria);
				
				$uniqueKey = $this->encrypt->get_random_password(10,10,false,true,false);
				
				$filePath = "reports";
				$fileName = "swamivisits_".$uniqueKey.".csv";
			
				$fp=fopen($filePath."/".$fileName,'a');
				
				$curdatetime = time();	
				$curdate = date('m/d/Y', $curdatetime);
				fwrite($fp, "\""."Date: ".$curdate."\"\n");
				$curtime = date('h:i:s A', $curdatetime);
				fwrite($fp, "Time: ".$curtime."\n");

				//---Search criteria----
				fwrite($fp, "Search Criteria:\n");
				
				if (!empty($searchcriteria['memberlastname']))
					fwrite($fp, "Registrant Last Name: ".$searchcriteria['memberlastname']."\n");
				else
					fwrite($fp, "Registrant Last Name: All\n");
				
				if (!empty($searchcriteria['memberfirstname']))
					fwrite($fp, "Registrant First Name: ".$searchcriteria['memberfirstname']."\n");
				else
					fwrite($fp, "Registrant First Name: All\n");

				if (!empty($searchcriteria['regstatus']))
					fwrite($fp, "Registration Status: ".$searchcriteria['regstatus']."\n");
				else
					fwrite($fp, "Registration Status: All\n");

				//----------------------

				fwrite($fp, "Number of search results: ".count($svinfo)."\n\n");
					
				fwrite($fp, "First Name,Last Name,Email,#Registered,Payment Status,Event\n");
				
				foreach( $svinfo as $svrec)
				{
					fwrite($fp, $svrec['firstname'].",".$svrec['lastname'].",".$svrec['email'].",".$svrec['numreg'].",".$svrec['paystatus'].",".$svrec['event']."\n");
				}				 

				fclose($fp);  // close file
				
				$this->session->unset_userdata( 'searchcriteria');
				
				$this->Reports_proxy->download_file( $filePath, $fileName );
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
		}

		public function download_banquet_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->model('proxies/annualbanquet/Annualbanquet_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$curyear = $this->Walk_proxy->getCurrentYear();			
			
			if ($this->Person_proxy->isPersonGroupRole( $personId, "member", "admin" ) or $this->Person_proxy->isPersonGroupRole( $personId, "member", "superadmin" ) or in_array("board",$group) or in_array("banquet",$group))
			{
				$searchcriteria = $this->session->userdata( 'searchcriteria');
	
				$bqinfo = $this->Reports_proxy->getBanquetAdminData($curyear, $searchcriteria);
				
				$uniqueKey = $this->encrypt->get_random_password(10,10,false,true,false);
				
                $filePath = "reports";
                $curdatetime = time();  
                $filedate = date('Y-m-d', $curdatetime);
                $fileName = "banquet_".$filedate.".csv";

				$fp=fopen($filePath."/".$fileName,'a');
				
				$curdate = date('m/d/Y', $curdatetime);
				fwrite($fp, "Date:,".$curdate."\n");
				$curtime = date('h:i:s A', $curdatetime);
				fwrite($fp, "Time:,".$curtime."\n");

				//---Search criteria----
				fwrite($fp, "Search Criteria:\n");
				
				if (!empty($searchcriteria['memberlastname']))
					fwrite($fp, "Registrant Last Name:,".$searchcriteria['memberlastname']."\n");
				else
					fwrite($fp, "Registrant Last Name:,All\n");
				
				if (!empty($searchcriteria['memberfirstname']))
					fwrite($fp, "Registrant First Name:,".$searchcriteria['memberfirstname']."\n");
				else
					fwrite($fp, "Registrant First Name:,All\n");

				if (!empty($searchcriteria['regstatus']))
					fwrite($fp, "Registration Status:,".$searchcriteria['regstatus']."\n");
				else
					fwrite($fp, "Registration Status:,All\n");

				//----------------------

				fwrite($fp, "Number of search results:,".count($bqinfo)."\n\n");
					
				fwrite($fp, "First Name,Last Name,Email,Phone,Address,City,State,Zip,#Registered,#Adults,#Children,Reg Fee,Donation,Teacher Discount,Total,Payment Status,Date Created\n");
				
				foreach( $bqinfo as $bqrec)
				{
					$totpersons = intval($bqrec['numadultreg']) + intval($bqrec['numchildreg']);
					
					fwrite($fp, $bqrec['firstname']);
					fwrite($fp, ",".$bqrec['lastname']);
					fwrite($fp, ",".$bqrec['email']);
					fwrite($fp, ",".$bqrec['phone']);
					fwrite($fp, ",".$bqrec['address']);
					fwrite($fp, ",".$bqrec['city']);
					fwrite($fp, ",".$bqrec['state']);
					fwrite($fp, ",".$bqrec['zip']);
					fwrite($fp, ",".$totpersons);
					fwrite($fp, ",".$bqrec['numadultreg']);
					fwrite($fp, ",".$bqrec['numchildreg']);
                    fwrite($fp, ",".$bqrec['reg_fee']);
                    fwrite($fp, ",".$bqrec['donation_amount']);
                    fwrite($fp, ",".$bqrec['teacher_discount']);
					fwrite($fp, ",".$bqrec['amount_paid']);
					fwrite($fp, ",".$bqrec['paystatus']);
                    fwrite($fp, ",".$bqrec['date_created']."\n");
				}				 

				fclose($fp);  // close file
				
				$this->session->unset_userdata( 'searchcriteria');
				
				$this->Reports_proxy->download_file( $filePath, $fileName );
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
		}
/*
		public function download_mahasamadhi_registrants_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->model('proxies/mahasamadhi/Mahasamadhi_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$curyear = $this->Mahasamadhi_proxy->getEventYear();			
			
			if (in_array("admin",$role) or in_array("superadmin",$role) or in_array("board",$group) or in_array("mahasamadhi",$group))
			{
				$searchcriteria = $this->session->userdata( 'searchcriteria');
	
				$mrhinfoarr = $this->Reports_proxy->getMahasamadhiRegistrantsData($curyear, $searchcriteria);
				
				$totarr = $this->Reports_proxy->getMahasamadhiRegistrantsTotals($curyear, $searchcriteria);
				
				$uniqueKey = $this->encrypt->get_random_password(10,10,false,true,false);
				
				$filePath = "reports";
				$fileName = "mahasamadhi_registrants_".$uniqueKey.".csv";
			
				$fp=fopen($filePath."/".$fileName,'a');
				
				$curdatetime = time();	
				$curdate = date('m/d/Y', $curdatetime);
				fwrite($fp, "\""."Date: ".$curdate."\"\n");
				$curtime = date('h:i:s A', $curdatetime);
				fwrite($fp, "Time: ".$curtime."\n");
				fwrite($fp, "Year: ".$curyear."\n");

				//---Search criteria----
				fwrite($fp, "Search Criteria:\n");
				
				if (!empty($searchcriteria['registrantlastname']))
					fwrite($fp, "Registrant Last Name: ".$searchcriteria['registrantlastname']."%\n");
				else
					fwrite($fp, "Registrant Last Name: All\n");
				
				if (!empty($searchcriteria['registrantfirstname']))
					fwrite($fp, "Registrant First Name: ".$searchcriteria['registrantfirstname']."%\n");
				else
					fwrite($fp, "Registrant First Name: All\n");

				if (!empty($searchcriteria['registrantcity']))
					fwrite($fp, "Registrant City: ".$searchcriteria['registrantcity']."%\n");
				else
					fwrite($fp, "Registrant City: All\n");

				if ((!empty($searchcriteria['registrantstate'])) and ($searchcriteria['registrantcountry'] != "All"))
					fwrite($fp, "Registrant State: ".$searchcriteria['registrantstate']."%\n");
				else
					fwrite($fp, "Registrant State: All\n");
				
				if ((!empty($searchcriteria['registrantcountry'])) and ($searchcriteria['registrantcountry'] != "All"))
					fwrite($fp, "Registrant Country: ".$searchcriteria['registrantcountry']."%\n");
				else
					fwrite($fp, "Registrant Country: All\n");
				//----------------------

				//---Search criteria----
				fwrite($fp, "Totals:\n");
				fwrite($fp, "Total # Adults: ".$totarr['adulttotal']."\n");
				fwrite($fp, "Total # Children: ".$totarr['childtotal']."\n");
				fwrite($fp, "Total # CHYK's: ".$totarr['chyktotal']."\n");
				fwrite($fp, "Total Amount Committed: $".$totarr['totcommitted']."\n");
				fwrite($fp, "Total Amount Paid: $".$totarr['totpaid']."\n");
				
				fwrite($fp, "Number of search results: ".count($mrhinfoarr)."\n\n");
					
				fwrite($fp, "Reg Code,");
				fwrite($fp, "First Name,");
				fwrite($fp, "Last Name,");
				fwrite($fp, "Referrer First Name,");
				fwrite($fp, "Referrer Last Name,");
				fwrite($fp, "City,");
				fwrite($fp, "State,");
				fwrite($fp, "Country,");
				//fwrite($fp, "Postal Code,");
				fwrite($fp, "Email,");
				fwrite($fp, "Phone,");
				fwrite($fp, "#Adult,");
				fwrite($fp, "#Child,");
				fwrite($fp, "#CHYK,");
				//fwrite($fp, "Total,");
				fwrite($fp, "Reg Type,");
				fwrite($fp, "Amount Committed,");
				fwrite($fp, "Amount Paid,");
				//fwrite($fp, "Pay Type,");
				//fwrite($fp, "Check Num,");
				fwrite($fp, "Pay Status\n");
				
				foreach( $mrhinfoarr as $mrhobj)
				{
					$mrv = Mahasamadhi_registration_value::cast( $mrhobj );
					fwrite($fp,$mrv->getRegCode());
					fwrite($fp,",".$mrv->getFirstName());
					fwrite($fp,",".$mrv->getLastName());
					fwrite($fp,",".$mrv->getCHYKRefFirstName());
					fwrite($fp,",".$mrv->getCHYKRefLastName());
					fwrite($fp,",".$mrv->getCity());
					fwrite($fp,",".$mrv->getState());
					fwrite($fp,",".$mrv->getCountry());
					//fwrite($fp,",".$mrv->getZip());
					fwrite($fp,",".$mrv->getEmail());
					fwrite($fp,",".$mrv->getPhone());
					fwrite($fp,",".$mrv->getNumAdultRegistered());
					fwrite($fp,",".$mrv->getNumChildRegistered());
					fwrite($fp,",".$mrv->getNumCHYKRegistered());
					//fwrite($fp,",".$mrv->getTotalNumRegistered());
					fwrite($fp,",".$mrv->getRegistrationTypeDescription());
					fwrite($fp,",".$mrv->getAmountCommitted());
					fwrite($fp,",".$mrv->getAmountPaid());
					//fwrite($fp,",".$mrv->getPaymentType());
					//fwrite($fp,",".$mrv->getCheckNum());

					switch ($mrv->getPaymentStatus())
					{
						case 0:
							fwrite($fp,",Unpaid\n");
							break;
						case 1:
							fwrite($fp,",Paid\n");
							break;
						case 2:
							fwrite($fp,",Pending\n");
							break;
						case 3:
							fwrite($fp,",Refund\n");
							break;
					}
				}				 

				fclose($fp);  // close file
				
				$this->session->unset_userdata( 'searchcriteria');
				
				$this->Reports_proxy->download_file( $filePath, $fileName );
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
		}

        public function download_mahasamadhi_detail_registrants_report( $urlKey )
        {
            $this->load->model('proxies/Person_proxy');
            $this->load->model('proxies/Walk_proxy');
            $this->load->model('proxies/Reports_proxy');
            $this->load->model('proxies/mahasamadhi/Mahasamadhi_proxy');
            $this->load->library('encrypt');
            
            $is_logged_in = $this->session->userdata( 'is_logged_in' );
            if (!$is_logged_in)
            {
                redirect( base_url() . 'cmb/member/login_home/' );
            }

            $seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
            if ($seckey != $this->session->userdata( 'logged_in_key' ))
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $personId = $this->session->userdata( 'person_id' );
            if ( $personId < 1 )
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $group = $this->Person_proxy->getPersonGroup( $personId );
            $role = $this->Person_proxy->getPersonRole( $personId );

            $curyear = $this->Mahasamadhi_proxy->getEventYear();            
            
            if (in_array("admin",$role) or in_array("superadmin",$role) or in_array("board",$group) or in_array("mahasamadhi",$group))
            {
                $searchcriteria = $this->session->userdata( 'searchcriteria');
    
                $mrhinfoarr = $this->Reports_proxy->getMahasamadhiDetailRegistrantsData($curyear, $searchcriteria);
                
                $uniqueKey = $this->encrypt->get_random_password(10,10,false,true,false);
                
                $filePath = "reports";
                $fileName = "mahasamadhi_registrants_detail_report.csv";
            
                $fp=fopen($filePath."/".$fileName,'a');
                
                $curdatetime = time();  
                $curdate = date('m/d/Y', $curdatetime);
                fwrite($fp, "Date:,\"".$curdate."\"\n");
                $curtime = date('h:i:s A', $curdatetime);
                fwrite($fp, "Time:,".$curtime."\n");

                //---Search criteria----
                fwrite($fp, "Search Criteria:\n");
                
                if (!empty($searchcriteria['registrantlastname']))
                    fwrite($fp, "Registrant Last Name:,".$searchcriteria['registrantlastname']."%\n");
                else
                    fwrite($fp, "Registrant Last Name:,All\n");
                
                if (!empty($searchcriteria['registrantfirstname']))
                    fwrite($fp, "Registrant First Name:,".$searchcriteria['registrantfirstname']."%\n");
                else
                    fwrite($fp, "Registrant First Name:,All\n");

                if (!empty($searchcriteria['registrantcity']))
                    fwrite($fp, "Registrant City:,".$searchcriteria['registrantcity']."%\n");
                else
                    fwrite($fp, "Registrant City:,All\n");

                if ((!empty($searchcriteria['registrantstate'])) and ($searchcriteria['registrantcountry'] != "All"))
                    fwrite($fp, "Registrant State:,".$searchcriteria['registrantstate']."%\n");
                else
                    fwrite($fp, "Registrant State:,All\n");
                
                if ((!empty($searchcriteria['registrantcountry'])) and ($searchcriteria['registrantcountry'] != "All"))
                    fwrite($fp, "Registrant Country:,".$searchcriteria['registrantcountry']."%\n");
                else
                    fwrite($fp, "Registrant Country:,All\n");
                //----------------------

                //---Search criteria----                
                fwrite($fp, "#Registrants:,".count($mrhinfoarr)."\n\n");
                    
                foreach( $mrhinfoarr as $mrhobj)
                {
                    fwrite($fp, "Reg Code,");
                    fwrite($fp, "Type,");
                    fwrite($fp, "Occupancy,");
                    fwrite($fp, "Ref FN,");
                    fwrite($fp, "Ref LN,");
                    fwrite($fp, "City,");
                    fwrite($fp, "State,");
                    fwrite($fp, "Country,");
                    fwrite($fp, "Postal Code,");
                    fwrite($fp, "Email,");
                    fwrite($fp, "Phone,");
                    fwrite($fp, "#Adult,");
                    fwrite($fp, "#Child,");
                    fwrite($fp, "#CHYK,");
                    fwrite($fp, "Amt Cmtd,");
                    fwrite($fp, "Amt Paid,");
                    fwrite($fp, "Pay Status,");
                    fwrite($fp, "Wheel Chair,");
                    fwrite($fp, "Special Needs Room,");
                    fwrite($fp, "Special Request,");
                    fwrite($fp, "Date Created\n");
                
                    $mrv = Mahasamadhi_registration_value::cast( $mrhobj );

                    if ($mrv->getSpecialNeedsWheelchair() == 0)
                        $snwc = "n/a";
                    else
                        $snwc = "yes";
        
                    if ($mrv->getSpecialNeedsRoom() == 0)
                        $snrm = "n/a";
                    else
                        $snrm = "yes";
        
                    $sr = $mrv->getSpecialRequests();

                    fwrite($fp,$mrv->getRegCode());
                    fwrite($fp,",\"".$mrv->getRegistrationTypeDescription()."\"");
                    fwrite($fp,",\"".$mrv->getRegistrationCaseDescription()."\"");
                    fwrite($fp,",\"".$mrv->getCHYKRefFirstName()."\"");
                    fwrite($fp,",\"".$mrv->getCHYKRefLastName()."\"");
                    fwrite($fp,",\"".$mrv->getCity()."\"");
                    fwrite($fp,",\"".$mrv->getState()."\"");
                    fwrite($fp,",\"".$mrv->getCountry()."\"");
                    fwrite($fp,",\"".$mrv->getZip()."\"");
                    fwrite($fp,",\"".$mrv->getEmail()."\"");
                    fwrite($fp,",\"".$mrv->getPhone()."\"");
                    fwrite($fp,",\"".$mrv->getNumAdultRegistered()."\"");
                    fwrite($fp,",\"".$mrv->getNumChildRegistered()."\"");
                    fwrite($fp,",\"".$mrv->getNumCHYKRegistered()."\"");
                    fwrite($fp,",\"".$mrv->getAmountCommitted()."\"");
                    fwrite($fp,",\"".$mrv->getAmountPaid()."\"");
                    switch (intval($mrv->getPaymentStatus()))
                    {
                        case 0:
                            fwrite($fp,",\"Unpaid\"");
                            break;
                        case 1:
                            fwrite($fp,",\"Paid\"");
                            break;
                        case 2:
                            fwrite($fp,",\"Pending\"");
                            break;
                        case 3:
                            fwrite($fp,",\"Refund\"");
                            break;
                    }
                    fwrite($fp,",\"".$snwc."\"");
                    fwrite($fp,",\"".$snrm."\"");
                    fwrite($fp,",\"".$sr."\"");
                    fwrite($fp,",\"".$mrv->getDateCreated()."\"\n");

                    if (($mrv->getNumAdultRegistered() > 0) || ($mrv->getNumCHYKRegistered() > 0)  || ($mrv->getNumChildRegistered() > 0))
                    {
                        fwrite($fp, "Type,");
                        fwrite($fp, "First Name,");
                        fwrite($fp, "Last Name,");
                        fwrite($fp, "Gender,");
                        fwrite($fp, "Age,");
                        fwrite($fp, "Diet Restrictions,");
                        fwrite($fp, "Allergies\n");
                    }
                
                    $numAdult = $mrv->getNumAdultRegistered();
                    if ($numAdult > 0)
                    {
                        for($i=0; $i<$numAdult; $i++)
                        {
                            $adultInfoArr = $mrv->getAdultInfo();
                            $adultRec = $adultInfoArr[$i];
                            
                            fwrite($fp,"\"Adult\",");                                                    
                            fwrite($fp,"\"".$adultRec["firstname"]."\"");
                            fwrite($fp,",\"".$adultRec["lastname"]."\"");
                            fwrite($fp,",\"".$adultRec["gender"]."\"");
                            fwrite($fp,",-");                        
                            if (trim($adultRec["dietrest"]) <> "")
                                fwrite($fp,",\"".$adultRec["dietrest"]."\"");
                            else
                                fwrite($fp,",\"none\"");
                            fwrite($fp,",\"".$adultRec["allergies"]."\"\n");
                        }                                
                    }
                    $numChild = $mrv->getNumChildRegistered();
                    if ($numChild > 0)
                    {
                        for($i=0; $i<$numChild; $i++)
                        {
                            $childInfoArr = $mrv->getChildInfo();
                            $childRec = $childInfoArr[$i];
                            
                            fwrite($fp,"\"Child\",");                                                    
                            fwrite($fp,"\"".$childRec["firstname"]."\"");
                            fwrite($fp,",\"".$childRec["lastname"]."\"");
                            fwrite($fp,",\"".$childRec["gender"]."\"");
                            fwrite($fp,",\"".$childRec["age"]."\"");
                            if (trim($childRec["dietrest"]) <> "")
                                fwrite($fp,",\"".$childRec["dietrest"]."\"");
                            else
                                fwrite($fp,",\"none\"");
                            fwrite($fp,",\"".$childRec["allergies"]."\"\n");
                        }                                
                    }

                    
                    $numCHYK = $mrv->getNumCHYKRegistered();
                    if ($numCHYK > 0)
                    {
                        for($i=0; $i<$numCHYK; $i++)
                        {
                            $chykInfoArr = $mrv->getCHYKInfo();
                            $chykRec = $chykInfoArr[$i];
                            
                            fwrite($fp,"\"CHYK\",");                                                    
                            fwrite($fp,"\"".$chykRec["firstname"]."\"");
                            fwrite($fp,",\"".$chykRec["lastname"]."\"");
                            fwrite($fp,",\"".$chykRec["gender"]."\"");
                            fwrite($fp,",-");                        
                            if (trim($chykRec["dietrest"]) <> "")
                                fwrite($fp,",\"".$chykRec["dietrest"]."\"");
                            else
                                fwrite($fp,",\"none\"");
                            fwrite($fp,",\"".$chykRec["allergies"]."\"\n");
                         }                                
                    }

                    if (($mrv->getNumBiksha() > 0) || ($mrv->getNumArathi() > 0))
                    {
                        fwrite($fp, "7/30,");
                        fwrite($fp, "7/31,");
                        fwrite($fp, "8/1,");
                        fwrite($fp, "8/2,");
                        fwrite($fp, "8/3\n");

                        if ($mrv->getNumBiksha() > 0)
                        { 
                            $eventname = array('Morning Bhiksha','Lunch Bhiksha','Evening Bhiksha');
                            $dayname = array('-','-','-','-','-');
                            $sessname = array('-','-','-','-','-');
                            for($i=0; $i<$mrv->getNumBiksha(); $i++)
                            {
                                $bikshaInfoArr = $mrv->getBikshaInfo();
                                $bikshaRec = $bikshaInfoArr[$i];
                                $dayid = intval($bikshaRec["dayid"]);
                                $sessid = intval($bikshaRec["eventid"]);
                                
                                $dayname[$dayid-1] = "+";
                                $sessname[$dayid-1] = $eventname[$sessid-1];
                            }

                            if ($dayname[0] != "-")
                                fwrite($fp,"\"".$sessname[0]."\"");
                            else
                                fwrite($fp,"-");                        
                            
                            for($i=1; $i<5; $i++)
                            {                       
                                if ($dayname[$i] != "-")
                                    fwrite($fp,",\"".$sessname[$i]."\"");
                                else
                                    fwrite($fp,",-");                        
                            }
                            fwrite($fp,"\n"); 
                        }
                        
                        if ($mrv->getNumArathi() > 0)
                        { 
                            $eventname = array('Morning Arathi','Lunch Arathi','Evening Arathi');
                            $dayname = array('-','-','-','-','-');
                            $sessname = array('-','-','-','-','-');
                            for($i=0; $i<$mrv->getNumArathi(); $i++)
                            {
                                $arathiInfoArr = $mrv->getArathiInfo();
                                $arathiRec = $arathiInfoArr[$i];
                                $dayid = intval($arathiRec["dayid"]);
                                $sessid = intval($arathiRec["eventid"]);
                                
                                $dayname[$dayid-1] = "+";
                                $sessname[$dayid-1] = $eventname[$sessid-1];
                            }

                            if ($dayname[0] != "-")
                                fwrite($fp,"\"".$sessname[0]."\"");
                            else
                                fwrite($fp,"-");                        
                            
                            for($i=1; $i<5; $i++)
                            {                       
                                if ($dayname[$i] != "-")
                                    fwrite($fp,",\"".$sessname[$i]."\"");
                                else
                                    fwrite($fp,",-");                        
                            }
                            fwrite($fp,"\n"); 
                        }
                    }                       

                    if (($mrv->getNumAdultRegistered() > 0) || ($mrv->getNumCHYKRegistered() > 0)  || ($mrv->getNumChildRegistered() > 0) || ($mrv->getNumBiksha() > 0) || ($mrv->getNumArathi() > 0))
                    {
                        fwrite($fp, "\n");
                    }
                }                

                fclose($fp);  // close file
                
                $this->session->unset_userdata( 'searchcriteria');
                
                $this->Reports_proxy->download_file( $filePath, $fileName );
            }
            else
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
        }

        public function download_mahasamadhi_hotel_registrants_report( $urlKey )
        {
            $this->load->model('proxies/Person_proxy');
            $this->load->model('proxies/Walk_proxy');
            $this->load->model('proxies/Reports_proxy');
            $this->load->model('proxies/mahasamadhi/Mahasamadhi_proxy');
            $this->load->library('encrypt');
            
            $is_logged_in = $this->session->userdata( 'is_logged_in' );
            if (!$is_logged_in)
            {
                redirect( base_url() . 'cmb/member/login_home/' );
            }

            $seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
            if ($seckey != $this->session->userdata( 'logged_in_key' ))
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $personId = $this->session->userdata( 'person_id' );
            if ( $personId < 1 )
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $group = $this->Person_proxy->getPersonGroup( $personId );
            $role = $this->Person_proxy->getPersonRole( $personId );

            $curyear = $this->Mahasamadhi_proxy->getEventYear();            
            
            if (in_array("admin",$role) or in_array("superadmin",$role) or in_array("board",$group) or in_array("mahasamadhi",$group))
            {
                $searchcriteria = $this->session->userdata( 'searchcriteria');
    
                $mrhinfoarr = $this->Reports_proxy->getMahasamadhiDetailRegistrantsData($curyear, $searchcriteria);
                
                $uniqueKey = $this->encrypt->get_random_password(10,10,false,true,false);
                
                $filePath = "reports";
                $fileName = "mahasamadhi_registrants_hotel_report.csv";
            
                $fp=fopen($filePath."/".$fileName,'a');
                
                $curdatetime = time();  
                $curdate = date('m/d/Y', $curdatetime);
                fwrite($fp, "Date:,\"".$curdate."\"\n");
                $curtime = date('h:i:s A', $curdatetime);
                fwrite($fp, "Time:,".$curtime."\n");
/*
                //---Search criteria----
                fwrite($fp, "Search Criteria:\n");
                
                if (!empty($searchcriteria['registrantlastname']))
                    fwrite($fp, "Registrant Last Name: ".$searchcriteria['registrantlastname']."%\n");
                else
                    fwrite($fp, "Registrant Last Name: All\n");
                
                if (!empty($searchcriteria['registrantfirstname']))
                    fwrite($fp, "Registrant First Name: ".$searchcriteria['registrantfirstname']."%\n");
                else
                    fwrite($fp, "Registrant First Name: All\n");

                if (!empty($searchcriteria['registrantcity']))
                    fwrite($fp, "Registrant City: ".$searchcriteria['registrantcity']."%\n");
                else
                    fwrite($fp, "Registrant City: All\n");

                if ((!empty($searchcriteria['registrantstate'])) and ($searchcriteria['registrantcountry'] != "All"))
                    fwrite($fp, "Registrant State: ".$searchcriteria['registrantstate']."%\n");
                else
                    fwrite($fp, "Registrant State: All\n");
                
                if ((!empty($searchcriteria['registrantcountry'])) and ($searchcriteria['registrantcountry'] != "All"))
                    fwrite($fp, "Registrant Country: ".$searchcriteria['registrantcountry']."%\n");
                else
                    fwrite($fp, "Registrant Country: All\n");
                //----------------------

                //---Search criteria----                
                fwrite($fp, "#Registrants:,".count($mrhinfoarr)."\n\n");
                    
                foreach( $mrhinfoarr as $mrhobj)
                {
                    fwrite($fp, "Reg Code,");
                    fwrite($fp, "Occupancy,");
                    fwrite($fp, "City,");
                    fwrite($fp, "State,");
                    fwrite($fp, "Country,");
                    fwrite($fp, "Postal Code,");
                    fwrite($fp, "Email,");
                    fwrite($fp, "Phone,");
                    fwrite($fp, "#Adult,");
                    fwrite($fp, "#Child,");
                    fwrite($fp, "Wheel Chair,");
                    fwrite($fp, "Special Needs Room,");
                    fwrite($fp, "Date Created\n");
                
                    $mrv = Mahasamadhi_registration_value::cast( $mrhobj );

                    if ($mrv->getSpecialNeedsWheelchair() == 0)
                        $snwc = "n/a";
                    else
                        $snwc = "yes";
        
                    if ($mrv->getSpecialNeedsRoom() == 0)
                        $snrm = "n/a";
                    else
                        $snrm = "yes";
        
                    $numAdult = $mrv->getNumAdultRegistered() + $mrv->getNumCHYKRegistered();

                    fwrite($fp,$mrv->getRegCode());
                    fwrite($fp,",\"".$mrv->getRegistrationCaseDescription()."\"");
                    fwrite($fp,",\"".$mrv->getCity()."\"");
                    fwrite($fp,",\"".$mrv->getState()."\"");
                    fwrite($fp,",\"".$mrv->getCountry()."\"");
                    fwrite($fp,",\"".$mrv->getZip()."\"");
                    fwrite($fp,",\"".$mrv->getEmail()."\"");
                    fwrite($fp,",\"".$mrv->getPhone()."\"");
                    fwrite($fp,",\"".$numAdult."\"");
                    fwrite($fp,",\"".$mrv->getNumChildRegistered()."\"");
                    fwrite($fp,",\"".$snwc."\"");
                    fwrite($fp,",\"".$snrm."\"");
                    fwrite($fp,",\"".$mrv->getDateCreated()."\"\n");

                    if (($mrv->getNumAdultRegistered() > 0) || ($mrv->getNumCHYKRegistered() > 0)  || ($mrv->getNumChildRegistered() > 0))
                    {
                        fwrite($fp, "First Name,");
                        fwrite($fp, "Last Name,");
                        fwrite($fp, "Gender,");
                        fwrite($fp, "Age\n");
                    }
                
                    $numAdult = $mrv->getNumAdultRegistered();
                    if ($numAdult > 0)
                    {
                        for($i=0; $i<$numAdult; $i++)
                        {
                            $adultInfoArr = $mrv->getAdultInfo();
                            $adultRec = $adultInfoArr[$i];
                            
                            fwrite($fp,"\"".$adultRec["firstname"]."\"");
                            fwrite($fp,",\"".$adultRec["lastname"]."\"");
                            fwrite($fp,",\"".$adultRec["gender"]."\"");
                            fwrite($fp,",\"Adult\"\n");                        
                        }                                
                    }
                    
                    $numCHYK = $mrv->getNumCHYKRegistered();
                    if ($numCHYK > 0)
                    {
                        for($i=0; $i<$numCHYK; $i++)
                        {
                            $chykInfoArr = $mrv->getCHYKInfo();
                            $chykRec = $chykInfoArr[$i];
                            
                            fwrite($fp,"\"".$chykRec["firstname"]."\"");
                            fwrite($fp,",\"".$chykRec["lastname"]."\"");
                            fwrite($fp,",\"".$chykRec["gender"]."\"");
                            fwrite($fp,",\"Adult\"\n");                        
                        }                                
                    }

                    $numChild = $mrv->getNumChildRegistered();
                    if ($numChild > 0)
                    {
                        for($i=0; $i<$numChild; $i++)
                        {
                            $childInfoArr = $mrv->getChildInfo();
                            $childRec = $childInfoArr[$i];
                            
                            fwrite($fp,"\"".$childRec["firstname"]."\"");
                            fwrite($fp,",\"".$childRec["lastname"]."\"");
                            fwrite($fp,",\"".$childRec["gender"]."\"");
                            fwrite($fp,",\"".$childRec["age"]."\"\n");
                        }                                
                    }

                    if (($mrv->getNumAdultRegistered() > 0) || ($mrv->getNumCHYKRegistered() > 0)  || ($mrv->getNumChildRegistered() > 0))
                    {
                        fwrite($fp, "\n");
                    }
                }                

                fclose($fp);  // close file
                
                $this->session->unset_userdata( 'searchcriteria');
                
                $this->Reports_proxy->download_file( $filePath, $fileName );
            }
            else
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
        }

        public function download_mahasamadhi_registrants_badge_report( $urlKey )
        {
            $this->load->model('proxies/Person_proxy');
            $this->load->model('proxies/Walk_proxy');
            $this->load->model('proxies/Reports_proxy');
            $this->load->model('proxies/mahasamadhi/Mahasamadhi_proxy');
            $this->load->library('encrypt');
            
            $is_logged_in = $this->session->userdata( 'is_logged_in' );
            if (!$is_logged_in)
            {
                redirect( base_url() . 'cmb/member/login_home/' );
            }

            $seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
            if ($seckey != $this->session->userdata( 'logged_in_key' ))
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $personId = $this->session->userdata( 'person_id' );
            if ( $personId < 1 )
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $group = $this->Person_proxy->getPersonGroup( $personId );
            $role = $this->Person_proxy->getPersonRole( $personId );

            $curyear = $this->Mahasamadhi_proxy->getEventYear();            
            
            if (in_array("admin",$role) or in_array("superadmin",$role) or in_array("board",$group) or in_array("mahasamadhi",$group))
            {
                $mrhinfoarr = $this->Reports_proxy->getMahasamadhiRegistrantsBadgeData($curyear);
                
                $uniqueKey = $this->encrypt->get_random_password(10,10,false,true,false);
                
                $filePath = "reports";
                $fileName = "mahasamadhi_registrants_badge_report.csv";
            
                $fp=fopen($filePath."/".$fileName,'a');
                
                $curdatetime = time();  
                $curdate = date('m/d/Y', $curdatetime);
                fwrite($fp, "Date:,\"".$curdate."\"\n");
                $curtime = date('h:i:s A', $curdatetime);
                fwrite($fp, "Time:,".$curtime."\n");
                    
                foreach( $mrhinfoarr as $mrhobj)
                {
                    fwrite($fp, "Reg Code,");
                
                    $mrv = Mahasamadhi_registration_value::cast( $mrhobj );

                    $numAdult = $mrv->getNumAdultRegistered() + $mrv->getNumCHYKRegistered();

                    fwrite($fp,$mrv->getRegCode()."\n");

                    if (($mrv->getNumAdultRegistered() > 0) || ($mrv->getNumCHYKRegistered() > 0)  || ($mrv->getNumChildRegistered() > 0))
                    {
                        fwrite($fp, "First Name,");
                        fwrite($fp, "Last Name,");
                        fwrite($fp, "Gender,");
                        fwrite($fp, "Age\n");
                    }
                
                    $numAdult = $mrv->getNumAdultRegistered();
                    if ($numAdult > 0)
                    {
                        for($i=0; $i<$numAdult; $i++)
                        {
                            $adultInfoArr = $mrv->getAdultInfo();
                            $adultRec = $adultInfoArr[$i];
                            
                            fwrite($fp,"\"".$adultRec["firstname"]."\"");
                            fwrite($fp,",\"".$adultRec["lastname"]."\"\n");
                            //fwrite($fp,",\"".$adultRec["gender"]."\"");
                            //fwrite($fp,",\"Adult\"\n");                        
                        }                                
                    }
                    
                    $numCHYK = $mrv->getNumCHYKRegistered();

                    if ($numCHYK > 0)
                    {
                        for($i=0; $i<$numCHYK; $i++)
                        {
                            $chykInfoArr = $mrv->getCHYKInfo();
                            $chykRec = $chykInfoArr[$i];
                            
                            fwrite($fp,"\"".$chykRec["firstname"]."\"");
                            fwrite($fp,",\"".$chykRec["lastname"]."\"\n");
                            //fwrite($fp,",\"".$chykRec["gender"]."\"");
                            //fwrite($fp,",\"Adult\"\n");                        
                        }                                
                    }

                    $numChild = $mrv->getNumChildRegistered();
                    if ($numChild > 0)
                    {
                        for($i=0; $i<$numChild; $i++)
                        {
                            $childInfoArr = $mrv->getChildInfo();
                            $childRec = $childInfoArr[$i];
                            
                            fwrite($fp,"\"".$childRec["firstname"]."\"");
                            fwrite($fp,",\"".$childRec["lastname"]."\"\n");
                            //fwrite($fp,",\"".$childRec["gender"]."\"");
                            //fwrite($fp,",\"".$childRec["age"]."\"\n");
                        }                                
                    }

                    if (($mrv->getNumAdultRegistered() > 0) || ($mrv->getNumCHYKRegistered() > 0)  || ($mrv->getNumChildRegistered() > 0))
                    {
                        fwrite($fp, "\n");
                    }
                }                

                fclose($fp);  // close file
                
                $this->Reports_proxy->download_file( $filePath, $fileName );
            }
            else
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
        }

        public function download_mahasamadhi_attendee_report( $urlKey )
        {
            $this->load->model('proxies/Person_proxy');
            $this->load->model('proxies/Walk_proxy');
            $this->load->model('proxies/Reports_proxy');
            $this->load->model('proxies/mahasamadhi/Mahasamadhi_proxy');
            $this->load->library('encrypt');
            
            $is_logged_in = $this->session->userdata( 'is_logged_in' );
            if (!$is_logged_in)
            {
                redirect( base_url() . 'cmb/member/login_home/' );
            }

            $seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
            if ($seckey != $this->session->userdata( 'logged_in_key' ))
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $personId = $this->session->userdata( 'person_id' );
            if ( $personId < 1 )
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $group = $this->Person_proxy->getPersonGroup( $personId );
            $role = $this->Person_proxy->getPersonRole( $personId );

            $curyear = $this->Mahasamadhi_proxy->getEventYear();            
            
            if (in_array("admin",$role) or in_array("superadmin",$role) or in_array("board",$group) or in_array("mahasamadhi",$group))
            {
                $mrhinfoarr = $this->Reports_proxy->getMahasamadhiRegistrantsBadgeData($curyear);
                
                $uniqueKey = $this->encrypt->get_random_password(10,10,false,true,false);
                
                $filePath = "reports";
                $fileName = "mahasamadhi_attendee_report.csv";
            
                $fp=fopen($filePath."/".$fileName,'a');
                
                $curdatetime = time();  
                $curdate = date('m/d/Y', $curdatetime);
                fwrite($fp, "Date:,\"".$curdate."\"\n");
                $curtime = date('h:i:s A', $curdatetime);
                fwrite($fp, "Time:,".$curtime."\n");
                    
                fwrite($fp, "\nReg Code,");
                fwrite($fp, "Reg Type,");
                fwrite($fp, "First Name,");
                fwrite($fp, "Last Name,");
                fwrite($fp, "Gender,");
                fwrite($fp, "Type,");
                fwrite($fp, "Age,\n");
                
                foreach( $mrhinfoarr as $mrhobj)
                {
                    $mrv = Mahasamadhi_registration_value::cast( $mrhobj );

                    $numAdult = $mrv->getNumAdultRegistered();
                    if ($numAdult > 0)
                    {
                        for($i=0; $i<$numAdult; $i++)
                        {
                            $adultInfoArr = $mrv->getAdultInfo();
                            $adultRec = $adultInfoArr[$i];
                            
                            fwrite($fp,$mrv->getRegCode());
                            fwrite($fp,",".$mrv->getRegistrationTypeDescription());
                            fwrite($fp,",\"".$adultRec["firstname"]."\"");
                            fwrite($fp,",\"".$adultRec["lastname"]."\"");
                            fwrite($fp,",\"".$adultRec["gender"]."\"");
                            fwrite($fp,",\"Adult\"");
                            fwrite($fp,",n/a\n");                         
                        }                                
                    }
                    
                    $numCHYK = $mrv->getNumCHYKRegistered();

                    if ($numCHYK > 0)
                    {
                        for($i=0; $i<$numCHYK; $i++)
                        {
                            $chykInfoArr = $mrv->getCHYKInfo();
                            $chykRec = $chykInfoArr[$i];
                            
                            fwrite($fp,$mrv->getRegCode());
                            fwrite($fp,",".$mrv->getRegistrationTypeDescription());
                            fwrite($fp,",\"".$chykRec["firstname"]."\"");
                            fwrite($fp,",\"".$chykRec["lastname"]."\"");
                            fwrite($fp,",\"".$chykRec["gender"]."\"");
                            fwrite($fp,",\"CHYK\"");
                            fwrite($fp,",n/a\n");                         
                        }                                
                    }

                    $numChild = $mrv->getNumChildRegistered();
                    if ($numChild > 0)
                    {
                        for($i=0; $i<$numChild; $i++)
                        {
                            $childInfoArr = $mrv->getChildInfo();
                            $childRec = $childInfoArr[$i];
                            
                            fwrite($fp,$mrv->getRegCode());
                            fwrite($fp,",".$mrv->getRegistrationTypeDescription());
                            fwrite($fp,",\"".$childRec["firstname"]."\"");
                            fwrite($fp,",\"".$childRec["lastname"]."\"");
                            fwrite($fp,",\"".$childRec["gender"]."\"");
                            fwrite($fp,",\"Child\"");
                            fwrite($fp,",\"".$childRec["age"]."\"\n");
                        }                                
                    }
                    
                    fwrite($fp, "\n");
                }                

                fclose($fp);  // close file
                
                $this->Reports_proxy->download_file( $filePath, $fileName );
            }
            else
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
        }

        //Report with each registration in one record
        public function download_mahasamadhi_hotel_special_report( $urlKey )
        {
            $this->load->model('proxies/Person_proxy');
            $this->load->model('proxies/Walk_proxy');
            $this->load->model('proxies/Reports_proxy');
            $this->load->model('proxies/mahasamadhi/Mahasamadhi_proxy');
            $this->load->library('encrypt');
            
            $is_logged_in = $this->session->userdata( 'is_logged_in' );
            if (!$is_logged_in)
            {
                redirect( base_url() . 'cmb/member/login_home/' );
            }

            $seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
            if ($seckey != $this->session->userdata( 'logged_in_key' ))
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $personId = $this->session->userdata( 'person_id' );
            if ( $personId < 1 )
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $group = $this->Person_proxy->getPersonGroup( $personId );
            $role = $this->Person_proxy->getPersonRole( $personId );

            $curyear = $this->Mahasamadhi_proxy->getEventYear();            
            
            if (in_array("admin",$role) or in_array("superadmin",$role) or in_array("board",$group) or in_array("mahasamadhi",$group))
            {
                $searchcriteria = $this->session->userdata( 'searchcriteria');
    
                $mrhinfoarr = $this->Reports_proxy->getMahasamadhiDetailRegistrantsData($curyear, $searchcriteria);
                
                $uniqueKey = $this->encrypt->get_random_password(10,10,false,true,false);
                
                $filePath = "reports";
                $fileName = "mahasamadhi_special_hotel_report.csv";
            
                $fp=fopen($filePath."/".$fileName,'a');
                
                $curdatetime = time();  
                $curdate = date('m/d/Y', $curdatetime);
                fwrite($fp, "Date:,\"".$curdate."\"\n");
                $curtime = date('h:i:s A', $curdatetime);
                fwrite($fp, "Time:,".$curtime."\n");
/*
                //---Search criteria----
                fwrite($fp, "Search Criteria:\n");
                
                if (!empty($searchcriteria['registrantlastname']))
                    fwrite($fp, "Registrant Last Name: ".$searchcriteria['registrantlastname']."%\n");
                else
                    fwrite($fp, "Registrant Last Name: All\n");
                
                if (!empty($searchcriteria['registrantfirstname']))
                    fwrite($fp, "Registrant First Name: ".$searchcriteria['registrantfirstname']."%\n");
                else
                    fwrite($fp, "Registrant First Name: All\n");

                if (!empty($searchcriteria['registrantcity']))
                    fwrite($fp, "Registrant City: ".$searchcriteria['registrantcity']."%\n");
                else
                    fwrite($fp, "Registrant City: All\n");

                if ((!empty($searchcriteria['registrantstate'])) and ($searchcriteria['registrantcountry'] != "All"))
                    fwrite($fp, "Registrant State: ".$searchcriteria['registrantstate']."%\n");
                else
                    fwrite($fp, "Registrant State: All\n");
                
                if ((!empty($searchcriteria['registrantcountry'])) and ($searchcriteria['registrantcountry'] != "All"))
                    fwrite($fp, "Registrant Country: ".$searchcriteria['registrantcountry']."%\n");
                else
                    fwrite($fp, "Registrant Country: All\n");
                //----------------------

                //---Search criteria----
                                
                fwrite($fp, "#Registrants:,".count($mrhinfoarr)."\n\n");
                    
                //Write ehader
                fwrite($fp, "Reg Code,");
                fwrite($fp, "Occupancy,");
                fwrite($fp, "City,");
                fwrite($fp, "State,");
                fwrite($fp, "Country,");
                fwrite($fp, "Postal Code,");
                fwrite($fp, "Email,");
                fwrite($fp, "Phone,");
                fwrite($fp, "#Adult,");
                fwrite($fp, "#Child,");
                fwrite($fp, "Wheel Chair,");
                fwrite($fp, "Special Needs Room,");
                fwrite($fp, "Date Created\n");
                
                foreach( $mrhinfoarr as $mrhobj)
                {
                    $mrv = Mahasamadhi_registration_value::cast( $mrhobj );

                    if ($mrv->getSpecialNeedsWheelchair() == 0)
                        $snwc = "n/a";
                    else
                        $snwc = "yes";
        
                    if ($mrv->getSpecialNeedsRoom() == 0)
                        $snrm = "n/a";
                    else
                        $snrm = "yes";
        
                    $numAdult = $mrv->getNumAdultRegistered() + $mrv->getNumCHYKRegistered();

                    fwrite($fp,$mrv->getRegCode());
                    fwrite($fp,",\"".$mrv->getRegistrationCaseDescription()."\"");
                    fwrite($fp,",\"".$mrv->getCity()."\"");
                    fwrite($fp,",\"".$mrv->getState()."\"");
                    fwrite($fp,",\"".$mrv->getCountry()."\"");
                    fwrite($fp,",\"".$mrv->getZip()."\"");
                    fwrite($fp,",\"".$mrv->getEmail()."\"");
                    fwrite($fp,",\"".$mrv->getPhone()."\"");
                    fwrite($fp,",\"".$numAdult."\"");
                    fwrite($fp,",\"".$mrv->getNumChildRegistered()."\"");
                    fwrite($fp,",\"".$snwc."\"");
                    fwrite($fp,",\"".$snrm."\"");
                    fwrite($fp,",\"".$mrv->getDateCreated()."\"");
                    
                    /*
                    if (($mrv->getNumAdultRegistered() > 0) || ($mrv->getNumCHYKRegistered() > 0)  || ($mrv->getNumChildRegistered() > 0))
                    {
                        fwrite($fp, "First Name,");
                        fwrite($fp, "Last Name,");
                        fwrite($fp, "Gender,");
                        fwrite($fp, "Age\n");
                    }

                    $numAdult = $mrv->getNumAdultRegistered();
                    if ($numAdult > 0)
                    {
                        for($i=0; $i<$numAdult; $i++)
                        {
                            $adultInfoArr = $mrv->getAdultInfo();
                            $adultRec = $adultInfoArr[$i];
                            
                            fwrite($fp,",\"".$adultRec["firstname"]."\"");
                            fwrite($fp,",\"".$adultRec["lastname"]."\"");
                            fwrite($fp,",\"".$adultRec["gender"]."\"");
                            fwrite($fp,",\"Adult\"");                        
                        }                                
                    }
                    
                    $numCHYK = $mrv->getNumCHYKRegistered();
                    if ($numCHYK > 0)
                    {
                        for($i=0; $i<$numCHYK; $i++)
                        {
                            $chykInfoArr = $mrv->getCHYKInfo();
                            $chykRec = $chykInfoArr[$i];
                            
                            fwrite($fp,",\"".$chykRec["firstname"]."\"");
                            fwrite($fp,",\"".$chykRec["lastname"]."\"");
                            fwrite($fp,",\"".$chykRec["gender"]."\"");
                            fwrite($fp,",\"Adult\"");                        
                        }                                
                    }

                    $numChild = $mrv->getNumChildRegistered();
                    if ($numChild > 0)
                    {
                        for($i=0; $i<$numChild; $i++)
                        {
                            $childInfoArr = $mrv->getChildInfo();
                            $childRec = $childInfoArr[$i];
                            
                            fwrite($fp,",\"".$childRec["firstname"]."\"");
                            fwrite($fp,",\"".$childRec["lastname"]."\"");
                            fwrite($fp,",\"".$childRec["gender"]."\"");
                            fwrite($fp,",\"".$childRec["age"]."\"");
                        }                                
                    }

                    fwrite($fp, "\n");
                }                

                fclose($fp);  // close file
                
                $this->session->unset_userdata( 'searchcriteria');
                
                $this->Reports_proxy->download_file( $filePath, $fileName );
            }
            else
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
        }
*/
		public function gen_reports( $urlKey )
		{
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Person_proxy');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}
			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$curyear = $this->Walk_proxy->getCurrentYear();

			$isAdmin = FALSE;
			if (($this->Person_proxy->isPersonGroupRole( $personId, "member", "admin" )) or ($this->Person_proxy->isPersonGroupRole( $personId, "member", "superadmin" )))
				$isAdmin = TRUE;
			
			$data['curyear'] = $this->Walk_proxy->getCurrentYear();
			$data['urlKey'] = $urlKey;
			$data['group'] = $group;
			$data['role'] = $role;
			$data['personId'] = $personId;
			$data['isAdmin'] = $isAdmin;
			
			$data['title'] = 'CMB Membership Reports - Admin';
			$data['view'] = 'cmb/reports/reports_admin_home_view';
/*
			if ($memberAdmin or in_array("superadmin",$role))
			{
				$data['title'] = 'CMB Membership Reports - Admin';
				$data['view'] = 'cmb/reports/reports_admin_home_view';
			}
			else
			{
				if (in_array("balavihar",$group))
				{
					
					//For Balavihar teachers
					$data['title'] = 'CMB Member Reports - Balavihar';
					//$data['view'] = 'cmb/reports/balavihar_reports_home_view';					
					$data['view'] = 'cmb/reports/reports_home_view';					
				}
				else
				{
						//For regular member users.
						$data['title'] = 'CMB Member Reports';
						$data['view'] = 'cmb/reports/reports_home_view';
				}
			}
*/						
			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}

		public function gen_reports_balavihar_home( $urlKey )
		{
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Person_proxy');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}
			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$curyear = $this->Walk_proxy->getCurrentYear();

			$data['curyear'] = $this->Walk_proxy->getCurrentYear();
			$data['urlKey'] = $urlKey;
			$data['group'] = $group;
			$data['role'] = $role;
			$data['personId'] = $personId;
			
			$memberAdmin = FALSE;
			if (($this->Person_proxy->isPersonGroupRole( $personId, "member", "admin" )) or ($this->Person_proxy->isPersonGroupRole( $personId, "member", "superadmin" )))
				$memberAdmin = TRUE;
			
			if ($memberAdmin or in_array("superadmin",$role))
			{
				$data['title'] = 'CMB Balavihar Admin Reports';
				$data['view'] = 'cmb/reports/reports_admin_balavihar_home_view';
			}
			else
			{
				if (in_array("balavihar",$group))
				{
					
					//For Balavihar teachers
					$data['title'] = 'CMB Balavihar Reports';
					$data['view'] = 'cmb/reports/reports_balavihar_home_view';					
				}
				else
				{
					redirect( base_url() . 'cmb/member/login_home/true/' );
				}
			}
						
			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}

		//General memebership reporting
		public function gen_reports_mahasamadhi_home( $urlKey )
		{
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Person_proxy');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}
			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$curyear = $this->Walk_proxy->getCurrentYear();

			$data['curyear'] = $this->Walk_proxy->getCurrentYear();
			$data['urlKey'] = $urlKey;
			$data['group'] = $group;
			$data['role'] = $role;
			$data['personId'] = $personId;
			
			$memberAdmin = FALSE;
			if (($this->Person_proxy->isPersonGroupRole( $personId, "member", "admin" )) or ($this->Person_proxy->isPersonGroupRole( $personId, "member", "superadmin" )) or ($this->Person_proxy->isPersonGroupRole( $personId, "mahasamadhi", "admin" )))
				$memberAdmin = TRUE;
			
			$data['isadmin'] = $memberAdmin;
			
			if ($memberAdmin or in_array("mahasamadhi",$group))
			{
				$data['title'] = 'Mahasamadhi Reports';
				$data['view'] = 'cmb/reports/reports_mahasamadhi_home_view';
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
						
			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}

		public function members_report_process( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			//$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}

			$curyear = $this->Walk_proxy->getCurrentYear();
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );
			
			$data['title'] = 'CMB Members Report';
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;

			if (in_array("board",$group) or in_array("admin",$role) or in_array("superadmin",$role))
			{
				$data['view'] = 'cmb/reports/members_admin_input_view';
			}
			else
			{
				$data['view'] = 'cmb/reports/members_input_view';
			}
			
			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				

		//General registration reporting
		public function registered_households_report_process( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			//$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}

			$curyear = $this->Walk_proxy->getCurrentYear();
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );
			
			$data['title'] = 'CMB Registered Primary Members in '.$curyear;
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;

			if (in_array("board",$group) or in_array("admin",$role) or in_array("superadmin",$role))
			{
				$data['view'] = 'cmb/reports/registered_households_admin_input_view';
			}
			else
			{
				$data['view'] = 'cmb/reports/registered_households_input_view';
			}
			
			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				

		//Balavihar search of registered children
		public function balavihar_report_process( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			//$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$curyear = $this->Walk_proxy->getCurrentYear();
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );
			
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;

			if (in_array("board",$group) or in_array("admin",$role) or in_array("superadmin",$role))
			{
				$data['title'] = 'CMB Admin Balavihar Reports for '.$curyear;
				$data['view'] = 'cmb/reports/balavihar_admin_input_view';
			}
			else
			{
				if (in_array("balavihar",$group))
				{
					$data['title'] = 'CMB Balavihar Reports for '.$curyear;
					$data['view'] = 'cmb/reports/balavihar_input_view';
				}
				else
				{
					redirect( base_url() . 'cmb/member/login_home/true/' );
				}				
			}

			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				

		//Balavihar class assignment list for teachers with input criteris
		public function balavihar_class_assignment_process( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$curyear = $this->Walk_proxy->getCurrentYear();
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );
			
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;

			if (in_array("board",$group) or in_array("admin",$role) or in_array("superadmin",$role))
			{
				$data['title'] = 'Balavihar Class Assignments for '.$curyear;
				$data['view'] = 'cmb/reports/balavihar_class_assignment_input_view';
			}
			else
			{
				if (in_array("balavihar",$group))
				{
					$data['title'] = 'Balavihar Class Assignments for '.$curyear;
					$data['view'] = 'cmb/reports/balavihar_class_assignment_input_view';
				}
				else
				{
					redirect( base_url() . 'cmb/member/login_home/true/' );
				}				
			}

			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				

        //Balavihar class assignment list for all classes
        public function balavihar_all_class_assignment_process( $urlKey )
        {
            $this->load->model('proxies/Person_proxy');
            $this->load->model('proxies/Walk_proxy');
            $this->load->library('encrypt');
            
            $is_logged_in = $this->session->userdata( 'is_logged_in' );
            if (!$is_logged_in)
            {
                redirect( base_url() . 'cmb/member/login_home/' );
            }

            $seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
            if ($seckey != $this->session->userdata( 'logged_in_key' ))
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $personId = $this->session->userdata( 'person_id' );
            if ( $personId < 1 )
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $curyear = $this->Walk_proxy->getCurrentYear();
            $group = $this->Person_proxy->getPersonGroup( $personId );
            $role = $this->Person_proxy->getPersonRole( $personId );
            
            $data['curyear'] = $curyear;
            $data['urlKey'] = $urlKey;

            if (in_array("board",$group) or in_array("admin",$role) or in_array("superadmin",$role))
            {
                $data['title'] = 'Balavihar All Class Assignments for '.$curyear;
                $data['view'] = 'cmb/reports/balavihar_all_class_assignment_input_view';
            }
            else
            {
                if (in_array("balavihar",$group))
                {
                    $data['title'] = 'Balavihar All Class Assignments for '.$curyear;
                    $data['view'] = 'cmb/reports/balavihar_all_class_assignment_input_view';
                }
                else
                {
                    redirect( base_url() . 'cmb/member/login_home/true/' );
                }               
            }

            $this->load->view( self::$REGISTRATION_TEMPLATE, $data );
        }               

		//Balavihar attendance by class
		public function balavihar_class_attendance_process( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$curyear = $this->Walk_proxy->getCurrentYear();
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );
			
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;

			if (in_array("board",$group) or in_array("admin",$role) or in_array("superadmin",$role))
			{
				$data['title'] = 'Balavihar Class Assignments for '.$curyear;
				$data['view'] = 'cmb/reports/balavihar_class_attendance_input_view';
			}
			else
			{
				if (in_array("balavihar",$group))
				{
					$data['title'] = 'Balavihar Class Attendance for '.$curyear;
					$data['view'] = 'cmb/reports/balavihar_class_attendance_input_view';
				}
				else
				{
					redirect( base_url() . 'cmb/member/login_home/true/' );
				}				
			}

			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				

		//Language reporting
		public function language_report_process( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			//$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$curyear = $this->Walk_proxy->getCurrentYear();
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );
			
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;

			if (in_array("board",$group) or in_array("admin",$role) or in_array("superadmin",$role) or in_array("balavihar",$group))
			{
				$data['title'] = 'CMB Admin Language Reports for '.$curyear;
				$data['view'] = 'cmb/reports/language_admin_input_view';
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}

			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				

		//Swami Visits reporting
		public function swamivisits_report_process( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}
			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			//$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$curyear = $this->Walk_proxy->getCurrentYear();
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );
			
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;

			if (($this->Person_proxy->isPersonGroupRole( $personId, "member", "admin" )) or ($this->Person_proxy->isPersonGroupRole( $personId, "member", "superadmin" )) or ($this->Person_proxy->isPersonGroupRole( $personId, "spiritual", "admin" )))
			{
				$data['title'] = 'CMB Swami Visits Report for '.$curyear;
				$data['view'] = 'cmb/reports/swamivisits_admin_input_view';
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );			
			}

			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				

		//Annual Banquet reporting
		public function banquet_report_process( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/annualbanquet/Annualbanquet_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$curyear = $this->Walk_proxy->getCurrentYear();
			$eventID = 1;
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );
			
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;

			if ($this->Person_proxy->isPersonGroupRole( $personId, "member", "admin" ) or $this->Person_proxy->isPersonGroupRole( $personId, "member", "superadmin" ) or in_array("board",$group) or in_array("banquet",$group))
			{
				$data['title'] = 'CMB '.$this->Annualbanquet_proxy->getEventName( $eventID).' for '.$curyear;
				$data['view'] = 'cmb/reports/banquet_admin_input_view';
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );			
			}

			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				

		public function members_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			//$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			$curyear = $this->Walk_proxy->getCurrentYear();
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$data['title'] = 'CMB Members';
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;
			
			if (in_array("board",$group) or in_array("admin",$role) or in_array("superadmin",$role))
			{
				$searchcriteria = array();
	
				$searchcriteria['memberlastname'] = $this->input->post('memberlastname');
				$searchcriteria['memberfirstname'] = $this->input->post('memberfirstname');
				$searchcriteria['membercity'] = $this->input->post('membercity');
				$searchcriteria['memberstate'] = $this->input->post('memberstate');
				$searchcriteria['centername'] = $this->input->post('centername');

				$this->session->set_userdata( 'searchcriteria', $searchcriteria );

				$reginfo = $this->Reports_proxy->getMembers($searchcriteria);
				
				$curyear = $this->Walk_proxy->getCurrentYear();
				
				$data['reginfo'] = $reginfo;
				$data['view'] = 'cmb/reports/members_admin_report_view';
			}
			else
			{
				$searchcriteria = array();
	
				$searchcriteria['memberlastname'] = $this->input->post('memberlastname');
				$searchcriteria['memberfirstname'] = $this->input->post('memberfirstname');
				$searchcriteria['membercity'] = $this->input->post('membercity');
				$searchcriteria['memberstate'] = $this->input->post('memberstate');
				$searchcriteria['centername'] = $this->input->post('centername');
				
				$reginfo = $this->Reports_proxy->getMembers($searchcriteria);
				
				$curyear = $this->Walk_proxy->getCurrentYear();
				
				$data['reginfo'] = $reginfo;
				$data['view'] = 'cmb/reports/members_report_view';				
			}
			
			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				

		//Management dashboard for current year
		public function management_dashboard_process( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}
			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			$curyear = $this->Walk_proxy->getCurrentYear();
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$data['title'] = 'CMB Balavihar Dashboard for '.$curyear.' - '.($curyear+1);
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;
			
			if (in_array("board",$group) or in_array("admin",$role) or in_array("superadmin",$role))
			{
				$dashinfoarr = $this->Reports_proxy->getManagementDashboardData($curyear);
/*				
				foreach($dashinfoarr as $dashrec)
				{
					echo $dashrec[0].','. $dashrec[1].','. $dashrec[2].','. $dashrec[3].','. $dashrec[4].','. $dashrec[5].','. $dashrec[6].','.$dashrec[7].','.$dashrec[8].'</br>';
				}
				
				die;
*/								
				$data['dashinfoarr'] = $dashinfoarr;
				$data['view'] = 'cmb/reports/management_dashboard_report_view';
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				

		//Summary data for all registered households for current year
		public function registered_households_summary_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			$curyear = $this->Walk_proxy->getCurrentYear();
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$data['title'] = 'CMB Registered Households Summary';
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;
			
			if (in_array("board",$group) or in_array("admin",$role) or in_array("superadmin",$role))
			{
				$curyear = $this->Walk_proxy->getCurrentYear();
				$reginfo = $this->Reports_proxy->getRegisteredMembersSummary($curyear);
								
				$data['reginfo'] = $reginfo;
				$data['view'] = 'cmb/reports/registered_households_summary_report_view';
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				

		//Search registered households for current year
		public function registered_households_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			//$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			$curyear = $this->Walk_proxy->getCurrentYear();
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$data['title'] = 'CMB Registered Households';
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;
			
			if (in_array("board",$group) or in_array("admin",$role) or in_array("superadmin",$role))
			{
				$searchcriteria = array();
	
				$searchcriteria['memberlastname'] = $this->input->post('memberlastname');
				$searchcriteria['memberfirstname'] = $this->input->post('memberfirstname');
				$searchcriteria['membercity'] = $this->input->post('membercity');
				$searchcriteria['memberstate'] = $this->input->post('memberstate');
				$searchcriteria['centername'] = $this->input->post('centername');
				$searchcriteria['paid'] = $this->input->post('paid');
				$searchcriteria['paytype'] = $this->input->post('paytype');
				$searchcriteria['memtype'] = $this->input->post('memtype');

				$this->session->set_userdata( 'searchcriteria', $searchcriteria );

				$reginfo = $this->Reports_proxy->getRegisteredMembersAdmin($curyear, $searchcriteria);
				
				$curyear = $this->Walk_proxy->getCurrentYear();
				
				$data['reginfo'] = $reginfo;
				$data['view'] = 'cmb/reports/registered_households_admin_report_view';
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				

		//Generate list of registered households for current year
		public function registered_households_list_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			//$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			$curyear = $this->Walk_proxy->getCurrentYear();
			$nextyear = ($this->Walk_proxy->getCurrentYear()+1);
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$data['title'] = 'CMB Registered Households for '.$curyear.'-'.$nextyear;
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;
			
			if (in_array("board",$group) or in_array("admin",$role) or in_array("superadmin",$role))
			{
				//Get all registered members in alphabetical order by last name
				$hhidarr = $this->Reports_proxy->getRegisteredHouseholdsAdmin( $curyear );
				
				//Get unregistered households info
				$householdinfo = $this->Reports_proxy->getHouseholdInfoAdmin( $hhidarr, $curyear );
				
				$curyear = $this->Walk_proxy->getCurrentYear();
				
				$data['householdinfo'] = $householdinfo;
				$data['view'] = 'cmb/reports/registered_households_admin_list_view';
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				

		//Generate list of unregistered households for current year
		public function unregistered_households_list_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			//$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			$curyear = $this->Walk_proxy->getCurrentYear();
			$nextyear = ($this->Walk_proxy->getCurrentYear()+1);
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$data['title'] = 'CMB Unregistered Households for '.$curyear.'-'.$nextyear;
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;
			
			if (in_array("board",$group) or in_array("admin",$role) or in_array("superadmin",$role))
			{
				//Get all unregistered members in alphabetical order by last name
				$hhidarr = $this->Reports_proxy->getUnregisteredHouseholdsAdmin( $curyear );
				
				//Get unregistered households info
				$householdinfo = $this->Reports_proxy->getHouseholdInfoAdmin( $hhidarr, ($curyear-1) );
				
				$curyear = $this->Walk_proxy->getCurrentYear();
				
				$data['householdinfo'] = $householdinfo;
				$data['view'] = 'cmb/reports/unregistered_households_admin_list_view';
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				

		//Generate list of registered tickets for current year
		public function registered_ticket_list_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			//$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			$curyear = $this->Walk_proxy->getCurrentYear();
			$nextyear = ($this->Walk_proxy->getCurrentYear()+1);
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$data['title'] = 'CMB Registered Household Tickets for '.$curyear.'-'.$nextyear;
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;
			
			if (in_array("board",$group) or in_array("admin",$role) or in_array("superadmin",$role))
			{
				//Get all registered members in alphabetical order by last name
				$hhidarr = $this->Reports_proxy->getRegisteredHouseholdsAdmin( $curyear );
				
				//Get registered households info
				$householdinfo = $this->Reports_proxy->getHouseholdInfoAdmin( $hhidarr, $curyear );
				
				$curyear = $this->Walk_proxy->getCurrentYear();
				
				$data['householdinfo'] = $householdinfo;
				$data['view'] = 'cmb/reports/registered_tickets_admin_list_view';
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				

		//Generate list of unregistered tickets for current year
		public function unregistered_ticket_list_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			//$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			$curyear = $this->Walk_proxy->getCurrentYear();
			$nextyear = ($this->Walk_proxy->getCurrentYear()+1);
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$data['title'] = 'CMB Unregistered Household Tickets for '.$curyear.'-'.$nextyear;
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;
			
			if (in_array("board",$group) or in_array("admin",$role) or in_array("superadmin",$role))
			{
				//Get all unregistered members in alphabetical order by last name
				$hhidarr = $this->Reports_proxy->getUnregisteredHouseholdsAdmin( $curyear );
				
				//Get unregistered households info
				$householdinfo = $this->Reports_proxy->getHouseholdInfoAdmin( $hhidarr, ($curyear-1) );
				
				$curyear = $this->Walk_proxy->getCurrentYear();
				
				$data['householdinfo'] = $householdinfo;
				$data['view'] = 'cmb/reports/unregistered_tickets_admin_list_view';
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				

		public function balavihar_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			//$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$curyear = $this->Walk_proxy->getCurrentYear();

			$data['title'] = 'CMB Balavihar Classes Report';
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;
			
			if (in_array("board",$group) or in_array("balavihar",$group) or in_array("admin",$role) or in_array("superadmin",$role))
			{
				$searchcriteria = array();
	
				$searchcriteria['memberlastname'] = $this->input->post('memberlastname');
				$searchcriteria['memberfirstname'] = $this->input->post('memberfirstname');
				$searchcriteria['membercity'] = $this->input->post('membercity');
				$searchcriteria['memberstate'] = $this->input->post('memberstate');
				$searchcriteria['centername'] = $this->input->post('centername');
				$searchcriteria['session'] = $this->input->post('session');
				$searchcriteria['gradename'] = $this->input->post('gradename');
				if ($this->input->post('year') == "Current")
					$specifiedyear = $curyear;
				else
					$specifiedyear = $curyear - 1;
				$searchcriteria['specifiedyear'] = $specifiedyear;
								
				$this->session->set_userdata( 'searchcriteria', $searchcriteria );

				$bvinfo = $this->Reports_proxy->getBalaviharAdminData($specifiedyear, $searchcriteria);

				$data['bvinfo'] = $bvinfo;
				$data['year'] = $specifiedyear;
				$data['view'] = 'cmb/reports/balavihar_admin_report_view';
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				

		public function balavihar_class_assignment_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$curyear = $this->Walk_proxy->getCurrentYear();

			$data['title'] = 'Balavihar Class Assignment Report';
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;
			
			if (in_array("board",$group) or in_array("balavihar",$group) or in_array("admin",$role) or in_array("superadmin",$role))
			{
				$searchcriteria = array();
	
				$searchcriteria['centername'] = $this->input->post('centername');
				$searchcriteria['session'] = $this->input->post('session');
				$searchcriteria['gradename'] = $this->input->post('gradename');
                $searchcriteria['status'] = $this->input->post('studentstatus');

				$this->session->set_userdata( 'searchcriteria', $searchcriteria );

				$bvinfo = $this->Reports_proxy->getBalaviharClassAssignmentData($curyear, $searchcriteria);
				
				If (count($bvinfo) > 0)
				{
					$data['centername'] = $this->input->post('centername');
					$data['session'] = $this->input->post('session');
					$data['gradename'] = $this->input->post('gradename');
                    $data['status'] = $this->input->post('studentstatus');
					$bvrec = $bvinfo[0];
					$data['teachers'] = $this->Reports_proxy->getTeachersFromGroup( $bvrec['teacher_group_id'] );
				}
				else
				{
					$data['centername'] = "n/a";
					$data['session'] = "n/a";
					$data['gradename'] = "n/a";
                    $data['status'] = "n/a";
				}

				$data['bvinfo'] = $bvinfo;
				$data['year'] = $curyear;
				$data['view'] = 'cmb/reports/balavihar_class_assignment_report_view';
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				

        public function balavihar_all_class_assignment_report( $urlKey )
        {
            $this->load->model('proxies/Person_proxy');
            $this->load->model('proxies/Walk_proxy');
            $this->load->model('proxies/Reports_proxy');
            $this->load->library('encrypt');
            
            $is_logged_in = $this->session->userdata( 'is_logged_in' );
            if (!$is_logged_in)
            {
                redirect( base_url() . 'cmb/member/login_home/' );
            }

            $seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
            if ($seckey != $this->session->userdata( 'logged_in_key' ))
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $personId = $this->session->userdata( 'person_id' );
            if ( $personId < 1 )
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $group = $this->Person_proxy->getPersonGroup( $personId );
            $role = $this->Person_proxy->getPersonRole( $personId );

            $curyear = $this->Walk_proxy->getCurrentYear();

            $data['title'] = 'Balavihar All Class Assignments Report';
            $data['curyear'] = $curyear;
            $data['urlKey'] = $urlKey;
            
            if (in_array("board",$group) or in_array("balavihar",$group) or in_array("admin",$role) or in_array("superadmin",$role))
            {
                $status = $this->input->post('studentstatus');
                $searchcriteria = array();    
                $searchcriteria['status'] = $status;

                $this->session->set_userdata( 'searchcriteria', $searchcriteria );

                $bvinfoall = array();
                    
                $centername = "Andover";
                $session = "AM";
                $gradename = "Pre-K";
                $bvinfo = $this->Reports_proxy->getBalaviharSpecificClassAssignmentData( $curyear, $centername, $session, $gradename, $status );
                foreach( $bvinfo as $bvrec)
                {
                    array_push($bvinfoall, $bvrec);
                }

                    
                $gradename = "K";
                $bvinfo = $this->Reports_proxy->getBalaviharSpecificClassAssignmentData( $curyear, $centername, $session, $gradename, $status );
                foreach( $bvinfo as $bvrec)
                {
                    array_push($bvinfoall, $bvrec);
                }

                for($k=1; $k<13; $k++)
                {
                    $gradename = strval($k);
                    $bvinfo = $this->Reports_proxy->getBalaviharSpecificClassAssignmentData( $curyear, $centername, $session, $gradename, $status );
                    foreach( $bvinfo as $bvrec)
                    {
                        array_push($bvinfoall, $bvrec);
                    }                    
                }

                $centername = "Andover";
                $session = "PM";
                $gradename = "Pre-K";
                $bvinfo = $this->Reports_proxy->getBalaviharSpecificClassAssignmentData( $curyear, $centername, $session, $gradename, $status );
                foreach( $bvinfo as $bvrec)
                {
                    array_push($bvinfoall, $bvrec);
                }

                    
                $gradename = "K";
                $bvinfo = $this->Reports_proxy->getBalaviharSpecificClassAssignmentData( $curyear, $centername, $session, $gradename, $status );
                foreach( $bvinfo as $bvrec)
                {
                    array_push($bvinfoall, $bvrec);
                }

                for($k=1; $k<10; $k++)
                {
                    $gradename = strval($k);
                    $bvinfo = $this->Reports_proxy->getBalaviharSpecificClassAssignmentData( $curyear, $centername, $session, $gradename, $status );
                    foreach( $bvinfo as $bvrec)
                    {
                        array_push($bvinfoall, $bvrec);
                    }                    
                }

                $centername = "Andover";
                $session = "PM2";
                $gradename = "Pre-K";
                $bvinfo = $this->Reports_proxy->getBalaviharSpecificClassAssignmentData( $curyear, $centername, $session, $gradename, $status );
                foreach( $bvinfo as $bvrec)
                {
                    array_push($bvinfoall, $bvrec);
                }

                    
                $gradename = "K";
                $bvinfo = $this->Reports_proxy->getBalaviharSpecificClassAssignmentData( $curyear, $centername, $session, $gradename, $status );
                foreach( $bvinfo as $bvrec)
                {
                    array_push($bvinfoall, $bvrec);
                }

                for($k=1; $k<9; $k++)
                {
                    $gradename = strval($k);
                    $bvinfo = $this->Reports_proxy->getBalaviharSpecificClassAssignmentData( $curyear, $centername, $session, $gradename, $status );
                    foreach( $bvinfo as $bvrec)
                    {
                        array_push($bvinfoall, $bvrec);
                    }                    
                }

                $centername = "MetroWest";
                $session = "PM";
                $gradename = "Pre-K";
                $bvinfo = $this->Reports_proxy->getBalaviharSpecificClassAssignmentData( $curyear, $centername, $session, $gradename, $status );
                foreach( $bvinfo as $bvrec)
                {
                    array_push($bvinfoall, $bvrec);
                }

                    
                $gradename = "K";
                $bvinfo = $this->Reports_proxy->getBalaviharSpecificClassAssignmentData( $curyear, $centername, $session, $gradename, $status );
                foreach( $bvinfo as $bvrec)
                {
                    array_push($bvinfoall, $bvrec);
                }

                for($k=1; $k<13; $k++)
                {
                    $gradename = strval($k);
                    $bvinfo = $this->Reports_proxy->getBalaviharSpecificClassAssignmentData( $curyear, $centername, $session, $gradename, $status );
                    foreach( $bvinfo as $bvrec)
                    {
                        array_push($bvinfoall, $bvrec);
                    }                    
                }

                $data['bvinfo'] = $bvinfoall;
                $data['year'] = $curyear;
                $data['view'] = 'cmb/reports/balavihar_all_class_assignment_report_view';
            }
            else
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $this->load->view( self::$REGISTRATION_TEMPLATE, $data );
        }               

		public function balavihar_class_attendance_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$curyear = $this->Walk_proxy->getCurrentYear();

			$data['title'] = 'Balavihar Class Attendance Report';
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;
			
			if (in_array("board",$group) or in_array("balavihar",$group) or in_array("admin",$role) or in_array("superadmin",$role))
			{
				$searchcriteria = array();
	
				$searchcriteria['centername'] = $this->input->post('centername');
				$searchcriteria['session'] = $this->input->post('session');
				$searchcriteria['gradename'] = $this->input->post('gradename');

				$this->session->set_userdata( 'searchcriteria', $searchcriteria );
				$this->session->set_userdata( 'outputformat', $this->input->post('outputformat') );
				$this->session->set_userdata( 'month', $this->input->post('month') );

				$bvattinfo = $this->Reports_proxy->getBalaviharClassAttendanceData($curyear, $searchcriteria);				
/*			
				echo "Number results: ".count($bvattinfo)."<br/>";
				echo "Number students: ".count($bvattinfo[0])."<br/>";
				die;
*/
				If (count($bvattinfo) > 0)
				{
					$data['centername'] = $this->input->post('centername');
					$data['session'] = $this->input->post('session');
					$data['gradename'] = $this->input->post('gradename');
					$data['outputformat'] = $this->input->post('outputformat');
					$data['specmonth'] = $this->input->post('month');
					$tmparr = $this->Walk_proxy->getBalaviharWeek($curyear);
					$curweekseq = $tmparr[1];
					$data['curweekseq'] = $curweekseq;
					$bvwkrec = $bvattinfo[0];
					$bvclass = $bvwkrec[0];
					$data['teachers'] = $this->Reports_proxy->getTeachersFromGroup( $bvclass[5] );
				}
				else
				{
					$data['centername'] = "n/a";
					$data['session'] = "n/a";
					$data['gradename'] = "n/a";
				}

				$data['bvattinfo'] = $bvattinfo;
				$data['year'] = $curyear;
				$data['view'] = 'cmb/reports/balavihar_class_attendance_report_view';
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				

		//Class attendance for currently logged in teacher
		public function balavihar_my_attendance_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );
			
			//Find all teacher groups associated with current login
			$teachingroups = $this->Walk_proxy->getTeacherGroups( $personId );
			if (count($teachingroups) <= 0)
			{
				echo "Member not part of any teaching group";
				die;
			}

			$curyear = $this->Walk_proxy->getCurrentYear();

			$data['title'] = 'Balavihar Class Attendance Report';
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;
			
			if (in_array("board",$group) or in_array("balavihar",$group) or in_array("admin",$role) or in_array("superadmin",$role))
			{
				$data['teachingroups'] = $teachingroups;

				$tginfoarr = array();
				$srchinfoarr = array();
				$teachersarr = array();
	
				foreach($teachingroups as $tgid)
				{
					$searchcriteria = array();				
					$srcharr = $this->Walk_proxy->getTeacherGroupCriteria( $curyear, $tgid );
					
					if (count($srcharr) > 0)
					{
						$searchcriteria['centername'] = $srcharr[0];
						$searchcriteria['session'] = $srcharr[1];
						$searchcriteria['gradename'] = $srcharr[2];
		
						$bvattinfo = $this->Reports_proxy->getBalaviharClassAttendanceData($curyear, $searchcriteria);
						
						array_push($tginfoarr, $bvattinfo);
						array_push($srchinfoarr, $searchcriteria);
						
						array_push($teachersarr, $this->Reports_proxy->getTeachersFromGroup( $tgid ));
					}
				}
/*			
				echo "Number results: ".count($bvattinfo)."<br/>";
				echo "Number students: ".count($bvattinfo[0])."<br/>";
				die;
*/
				If (count($tginfoarr) > 0)
				{
					$data['srchinfoarr'] = $srchinfoarr;
					$tmparr = $this->Walk_proxy->getBalaviharWeek($curyear);
					$curweekseq = $tmparr[1];
					$data['curweekseq'] = $curweekseq;
					$bvwkrec = $bvattinfo[0];
					$bvclass = $bvwkrec[0];
					$data['teachersarr'] = $teachersarr;
				}
				else
				{
					$data['centername'] = "n/a";
					$data['session'] = "n/a";
					$data['gradename'] = "n/a";
				}

				$data['tginfoarr'] = $tginfoarr;
				$data['year'] = $curyear;
				$data['view'] = 'cmb/reports/balavihar_my_attendance_report_view';
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				

		//Balavihar class roster report for currently logged in teacher
		public function balavihar_class_roster_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$curyear = $this->Walk_proxy->getCurrentYear();
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );
			
			//Find all teacher groups associated with current login
			$teachingroups = $this->Walk_proxy->getTeacherGroups( $personId );
			
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;
			$data['title'] = 'Balavihar All Class Roster for '.$curyear;
			$data['view'] = 'cmb/reports/balavihar_class_roster_report_view';

			if (count($teachingroups) > 0)
			{
				$data['teachingroups'] = $teachingroups;
				
				if (in_array("board",$group) or in_array("admin",$role) or in_array("superadmin",$role) or in_array("balavihar",$group))
				{
					$status = "All";
					$tginfo = $this->Reports_proxy->getClassRosterData($curyear, $teachingroups, $status);
					$data['tginfo'] = $tginfo;
				}
				else
				{
					redirect( base_url() . 'cmb/member/login_home/true/' );				
				}
			}
			else
			
			{
				echo "Member not part of any teaching group";
				die;
			}

			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				

        //Balavihar class roster report for registred children for currently logged in teacher
        public function balavihar_registered_class_roster_report( $urlKey )
        {
            $this->load->model('proxies/Person_proxy');
            $this->load->model('proxies/Walk_proxy');
            $this->load->model('proxies/Reports_proxy');
            $this->load->library('encrypt');
            
            $is_logged_in = $this->session->userdata( 'is_logged_in' );
            if (!$is_logged_in)
            {
                redirect( base_url() . 'cmb/member/login_home/' );
            }

            //$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );            
            $seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
            if ($seckey != $this->session->userdata( 'logged_in_key' ))
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $personId = $this->session->userdata( 'person_id' );
            if ( $personId < 1 )
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $curyear = $this->Walk_proxy->getCurrentYear();
            $group = $this->Person_proxy->getPersonGroup( $personId );
            $role = $this->Person_proxy->getPersonRole( $personId );
            
            //Find all teacher groups associated with current login
            $teachingroups = $this->Walk_proxy->getTeacherGroups( $personId );
            
            $data['curyear'] = $curyear;
            $data['urlKey'] = $urlKey;
            $data['title'] = 'Balavihar Registered Class Roster for '.$curyear;
            $data['view'] = 'cmb/reports/balavihar_registered_class_roster_report_view';

            if (count($teachingroups) > 0)
            {
                $data['teachingroups'] = $teachingroups;
                
                if (in_array("board",$group) or in_array("admin",$role) or in_array("superadmin",$role) or in_array("balavihar",$group))
                {
                    $status = "Registered";
                    $tginfo = $this->Reports_proxy->getClassRosterData($curyear, $teachingroups, $status);
                    $data['tginfo'] = $tginfo;
                }
                else
                {
                    redirect( base_url() . 'cmb/member/login_home/true/' );             
                }
            }
            else
            
            {
                echo "Member not part of any teaching group";
                die;
            }

            $this->load->view( self::$REGISTRATION_TEMPLATE, $data );
        }               

		public function language_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			//$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$curyear = $this->Walk_proxy->getCurrentYear();

			$data['title'] = 'CMB Language Classes Report';
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;
			
			if (in_array("board",$group) or in_array("admin",$role) or in_array("superadmin",$role) or in_array("balavihar",$group))
			{
				$searchcriteria = array();
	
				$searchcriteria['memberlastname'] = $this->input->post('memberlastname');
				$searchcriteria['memberfirstname'] = $this->input->post('memberfirstname');
				$searchcriteria['membercity'] = $this->input->post('membercity');
				$searchcriteria['memberstate'] = $this->input->post('memberstate');
				$searchcriteria['centername'] = $this->input->post('centername');
				$searchcriteria['languagename'] = $this->input->post('languagename');

				$this->session->set_userdata( 'searchcriteria', $searchcriteria );

				$langinfo = $this->Reports_proxy->getLanguageAdminData($curyear, $searchcriteria);
								
				$data['langinfo'] = $langinfo;
				$data['view'] = 'cmb/reports/language_admin_report_view';
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				

		public function swamivisits_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			//$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$curyear = $this->Walk_proxy->getCurrentYear();

			$data['title'] = 'CMB Swami Visits Report';
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;
			
			if (($this->Person_proxy->isPersonGroupRole( $personId, "member", "admin" )) or ($this->Person_proxy->isPersonGroupRole( $personId, "member", "superadmin" )) or ($this->Person_proxy->isPersonGroupRole( $personId, "spiritual", "admin" )))
			{
				$searchcriteria = array();
	
				$searchcriteria['memberlastname'] = $this->input->post('memberlastname');
				$searchcriteria['memberfirstname'] = $this->input->post('memberfirstname');
				$searchcriteria['regstatus'] = $this->input->post('regstatus');

				$this->session->set_userdata( 'searchcriteria', $searchcriteria );

				$svinfo = $this->Reports_proxy->getSwamivisitsAdminData($curyear, $searchcriteria);

				$data['svinfo'] = $svinfo;
				$data['view'] = 'cmb/reports/swamivisits_admin_report_view';
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				

		public function banquet_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->model('proxies/annualbanquet/Annualbanquet_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$curyear = $this->Walk_proxy->getCurrentYear();
			$eventID = 1;

			$data['title'] = 'CMB '.$this->Annualbanquet_proxy->getEventName( $eventID).' for '.$curyear;
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;
			
			if ($this->Person_proxy->isPersonGroupRole( $personId, "member", "admin" ) or $this->Person_proxy->isPersonGroupRole( $personId, "member", "superadmin" ) or in_array("board",$group) or in_array("banquet",$group))
			{
				$searchcriteria = array();
	
				$searchcriteria['memberlastname'] = $this->input->post('memberlastname');
				$searchcriteria['memberfirstname'] = $this->input->post('memberfirstname');
				$searchcriteria['regstatus'] = $this->input->post('regstatus');

				$this->session->set_userdata( 'searchcriteria', $searchcriteria );

				$bqinfo = $this->Reports_proxy->getBanquetAdminData($curyear, $searchcriteria);

				$data['bqinfo'] = $bqinfo;
				$data['view'] = 'cmb/reports/banquet_admin_report_view';
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				

		//Search of Mahasamadi registrants
		public function mahasamadhi_registrants_report_process( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/mahasamadhi/Mahasamadhi_proxy');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$curyear = $this->Mahasamadhi_proxy->getEventYear();
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );
			
			//Get list of countries
			$country_list = $this->Walk_proxy->getCountryList();
			
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;
			$data['country_list'] = $country_list;

			if (in_array("board",$group) or in_array("admin",$role) or in_array("superadmin",$role))
			{
				$data['title'] = 'Mahasamadhi Camp Registrants Search';
				$data['view'] = 'cmb/reports/mahasamadhi_input_view';
			}
			else
			{
				if (in_array("mahasamadhi",$group))
				{
					$data['title'] = 'Mahasamadhi Camp Registrants Search';
					$data['view'] = 'cmb/reports/mahasamadhi_input_view';
				}
				else
				{
					redirect( base_url() . 'cmb/member/login_home/true/' );
				}				
			}

			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				

        //Search of Mahasamadi registrants for detailed report
        public function mahasamadhi_registrants_detail_report_process( $urlKey )
        {
            $this->load->model('proxies/Person_proxy');
            $this->load->model('proxies/Walk_proxy');
            $this->load->model('proxies/mahasamadhi/Mahasamadhi_proxy');
            
            $is_logged_in = $this->session->userdata( 'is_logged_in' );
            if (!$is_logged_in)
            {
                redirect( base_url() . 'cmb/member/login_home/' );
            }

            $seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
            if ($seckey != $this->session->userdata( 'logged_in_key' ))
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $personId = $this->session->userdata( 'person_id' );
            if ( $personId < 1 )
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $curyear = $this->Mahasamadhi_proxy->getEventYear();
            $group = $this->Person_proxy->getPersonGroup( $personId );
            $role = $this->Person_proxy->getPersonRole( $personId );
            
            //Get list of countries
            $country_list = $this->Walk_proxy->getCountryList();
            
            $data['curyear'] = $curyear;
            $data['urlKey'] = $urlKey;
            $data['country_list'] = $country_list;

            if (in_array("board",$group) or in_array("admin",$role) or in_array("superadmin",$role))
            {
                $data['title'] = 'Mahasamadhi Camp Detail Registrants Search';
                $data['view'] = 'cmb/reports/mahasamadhi_detail_input_view';
            }
            else
            {
                if (in_array("mahasamadhi",$group))
                {
                    $data['title'] = 'Mahasamadhi Camp Registrants Search';
                    $data['view'] = 'cmb/reports/mahasamadhi_detail_input_view';
                }
                else
                {
                    redirect( base_url() . 'cmb/member/login_home/true/' );
                }               
            }

            $this->load->view( self::$REGISTRATION_TEMPLATE, $data );
        }               

        //Search of Mahasamadi registrants for hotel report
        public function mahasamadhi_registrants_hotel_report_process( $urlKey )
        {
            $this->load->model('proxies/Person_proxy');
            $this->load->model('proxies/Walk_proxy');
            $this->load->model('proxies/mahasamadhi/Mahasamadhi_proxy');
            
            $is_logged_in = $this->session->userdata( 'is_logged_in' );
            if (!$is_logged_in)
            {
                redirect( base_url() . 'cmb/member/login_home/' );
            }

            $seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
            if ($seckey != $this->session->userdata( 'logged_in_key' ))
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $personId = $this->session->userdata( 'person_id' );
            if ( $personId < 1 )
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $curyear = $this->Mahasamadhi_proxy->getEventYear();
            $group = $this->Person_proxy->getPersonGroup( $personId );
            $role = $this->Person_proxy->getPersonRole( $personId );
            
            //Get list of countries
            $country_list = $this->Walk_proxy->getCountryList();
            
            $data['curyear'] = $curyear;
            $data['urlKey'] = $urlKey;
            $data['country_list'] = $country_list;

            if (in_array("board",$group) or in_array("admin",$role) or in_array("superadmin",$role))
            {
                $data['title'] = 'Mahasamadhi Camp Hotel Registrants Search';
                $data['view'] = 'cmb/reports/mahasamadhi_hotel_input_view';
            }
            else
            {
                if (in_array("mahasamadhi",$group))
                {
                    $data['title'] = 'Mahasamadhi Camp Hotel Registrants Search';
                    $data['view'] = 'cmb/reports/mahasamadhi_hotel_input_view';
                }
                else
                {
                    redirect( base_url() . 'cmb/member/login_home/true/' );
                }               
            }

            $this->load->view( self::$REGISTRATION_TEMPLATE, $data );
        }               

		public function mahasamadhi_registrants_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/mahasamadhi/Mahasamadhi_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
						
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			//$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$curyear = $this->Mahasamadhi_proxy->getEventYear();

			$data['title'] = 'Mahasamadhi Camp Registrants Summary Report';
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;
			
			if (in_array("board",$group) or in_array("mahasamadhi",$group) or in_array("admin",$role) or in_array("superadmin",$role))
			{
				$searchcriteria = array();
	
				$searchcriteria['registrantlastname'] = $this->input->post('registrantlastname');
				$searchcriteria['registrantfirstname'] = $this->input->post('registrantfirstname');
				$searchcriteria['registrantcity'] = $this->input->post('registrantcity');
				$searchcriteria['registrantcountry'] = $this->input->post('country');

				if ($this->input->post('country') == "US")
				{
					$searchcriteria['registrantstate'] = $this->input->post('stateusa');
				}
				else
				{
					$searchcriteria['registrantstate'] = $this->input->post('stateglobal');
				}
								
				$this->session->set_userdata( 'searchcriteria', $searchcriteria );

				$mrhinfoarr = $this->Reports_proxy->getMahasamadhiRegistrantsData($curyear, $searchcriteria);
				
				$totarr = $this->Reports_proxy->getMahasamadhiRegistrantsTotals($curyear, $searchcriteria);

				//echo('Number of registrants: '.count($mrhinfoarr));
				//die;
				
				$data['mrhinfoarr'] = $mrhinfoarr;
				$data['totarr'] = $totarr;
				$data['year'] = $curyear;
				$data['searchcriteria'] = $searchcriteria;
				$data['year'] = $curyear;
				$data['view'] = 'cmb/reports/mahasamadhi_registrants_report_view';
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				

        public function mahasamadhi_detail_registrants_report( $urlKey )
        {
            $this->load->model('proxies/Person_proxy');
            $this->load->model('proxies/mahasamadhi/Mahasamadhi_proxy');
            $this->load->model('proxies/Reports_proxy');
            $this->load->library('encrypt');
            
            $is_logged_in = $this->session->userdata( 'is_logged_in' );
            if (!$is_logged_in)
            {
                redirect( base_url() . 'cmb/member/login_home/' );
            }

            //$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );            
            $seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
            if ($seckey != $this->session->userdata( 'logged_in_key' ))
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            //$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
            $personId = $this->session->userdata( 'person_id' );
            if ( $personId < 1 )
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $group = $this->Person_proxy->getPersonGroup( $personId );
            $role = $this->Person_proxy->getPersonRole( $personId );

            $curyear = $this->Mahasamadhi_proxy->getEventYear();

            $data['title'] = 'Mahasamadhi Camp Detail Registrants Summary Report';
            $data['curyear'] = $curyear;
            $data['urlKey'] = $urlKey;
            
            if (in_array("board",$group) or in_array("mahasamadhi",$group) or in_array("admin",$role) or in_array("superadmin",$role))
            {
                $searchcriteria = array();
    
                $searchcriteria['registrantlastname'] = $this->input->post('registrantlastname');
                $searchcriteria['registrantfirstname'] = $this->input->post('registrantfirstname');
                $searchcriteria['registrantcity'] = $this->input->post('registrantcity');
                $searchcriteria['registrantcountry'] = $this->input->post('country');

                if ($this->input->post('country') == "US")
                {
                    $searchcriteria['registrantstate'] = $this->input->post('stateusa');
                }
                else
                {
                    $searchcriteria['registrantstate'] = $this->input->post('stateglobal');
                }
                                
                $this->session->set_userdata( 'searchcriteria', $searchcriteria );

                $mrhinfoarr = $this->Reports_proxy->getMahasamadhiDetailRegistrantsData($curyear, $searchcriteria);

                //echo('Number of registrants: '.count($mrhinfoarr));
                //die;
                
                $data['mrhinfoarr'] = $mrhinfoarr;
                $data['year'] = $curyear;
                $data['searchcriteria'] = $searchcriteria;
                $data['year'] = $curyear;
                $data['view'] = 'cmb/reports/mahasamadhi_detail_registrants_report_view';
            }
            else
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $this->load->view( self::$REGISTRATION_TEMPLATE, $data );
        }               

        public function mahasamadhi_hotel_registrants_report( $urlKey )
        {
            $this->load->model('proxies/Person_proxy');
            $this->load->model('proxies/mahasamadhi/Mahasamadhi_proxy');
            $this->load->model('proxies/Reports_proxy');
            $this->load->library('encrypt');
            
            $is_logged_in = $this->session->userdata( 'is_logged_in' );
            if (!$is_logged_in)
            {
                redirect( base_url() . 'cmb/member/login_home/' );
            }

            //$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );            
            $seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
            if ($seckey != $this->session->userdata( 'logged_in_key' ))
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            //$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
            $personId = $this->session->userdata( 'person_id' );
            if ( $personId < 1 )
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $group = $this->Person_proxy->getPersonGroup( $personId );
            $role = $this->Person_proxy->getPersonRole( $personId );

            $curyear = $this->Mahasamadhi_proxy->getEventYear();

            $data['title'] = 'Mahasamadhi Camp Registrants Hotel Report';
            $data['curyear'] = $curyear;
            $data['urlKey'] = $urlKey;
            
            if (in_array("board",$group) or in_array("mahasamadhi",$group) or in_array("admin",$role) or in_array("superadmin",$role))
            {
                $searchcriteria = array();
    
                $searchcriteria['registrantlastname'] = $this->input->post('registrantlastname');
                $searchcriteria['registrantfirstname'] = $this->input->post('registrantfirstname');
                $searchcriteria['registrantcity'] = $this->input->post('registrantcity');
                $searchcriteria['registrantcountry'] = $this->input->post('country');

                if ($this->input->post('country') == "US")
                {
                    $searchcriteria['registrantstate'] = $this->input->post('stateusa');
                }
                else
                {
                    $searchcriteria['registrantstate'] = $this->input->post('stateglobal');
                }
                                
                $this->session->set_userdata( 'searchcriteria', $searchcriteria );

                $mrhinfoarr = $this->Reports_proxy->getMahasamadhiDetailRegistrantsData($curyear, $searchcriteria);

                //echo('Number of registrants: '.count($mrhinfoarr));
                //die;
                
                $data['mrhinfoarr'] = $mrhinfoarr;
                $data['year'] = $curyear;
                $data['searchcriteria'] = $searchcriteria;
                $data['year'] = $curyear;
                $data['view'] = 'cmb/reports/mahasamadhi_hotel_registrants_report_view';
            }
            else
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $this->load->view( self::$REGISTRATION_TEMPLATE, $data );
        }               

        public function mahasamadhi_registrants_badge_report( $urlKey )
        {
            $this->load->model('proxies/Person_proxy');
            $this->load->model('proxies/mahasamadhi/Mahasamadhi_proxy');
            $this->load->model('proxies/Reports_proxy');
            $this->load->library('encrypt');
            
            $is_logged_in = $this->session->userdata( 'is_logged_in' );
            if (!$is_logged_in)
            {
                redirect( base_url() . 'cmb/member/login_home/' );
            }

            //$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );            
            $seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
            if ($seckey != $this->session->userdata( 'logged_in_key' ))
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            //$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
            $personId = $this->session->userdata( 'person_id' );
            if ( $personId < 1 )
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $group = $this->Person_proxy->getPersonGroup( $personId );
            $role = $this->Person_proxy->getPersonRole( $personId );

            $curyear = $this->Mahasamadhi_proxy->getEventYear();

            $data['title'] = 'Mahasamadhi Camp Registrants Badge Report';
            
            if (in_array("board",$group) or in_array("mahasamadhi",$group) or in_array("admin",$role) or in_array("superadmin",$role))
            {
                $mrhinfoarr = $this->Reports_proxy->getMahasamadhiRegistrantsBadgeData($curyear);

                //echo('Number of registrants: '.count($mrhinfoarr));
                //die;
                
                $data['mrhinfoarr'] = $mrhinfoarr;
                $data['year'] = $curyear;
                $data['urlKey'] = $urlKey;
                $data['view'] = 'cmb/reports/mahasamadhi_registrants_badge_report_view';
            }
            else
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $this->load->view( self::$REGISTRATION_TEMPLATE, $data );
        }               

        public function mahasamadhi_attendee_report( $urlKey )
        {
            $this->load->model('proxies/Person_proxy');
            $this->load->model('proxies/mahasamadhi/Mahasamadhi_proxy');
            $this->load->model('proxies/Reports_proxy');
            $this->load->library('encrypt');
            
            $is_logged_in = $this->session->userdata( 'is_logged_in' );
            if (!$is_logged_in)
            {
                redirect( base_url() . 'cmb/member/login_home/' );
            }

            //$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );            
            $seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
            if ($seckey != $this->session->userdata( 'logged_in_key' ))
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            //$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
            $personId = $this->session->userdata( 'person_id' );
            if ( $personId < 1 )
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $group = $this->Person_proxy->getPersonGroup( $personId );
            $role = $this->Person_proxy->getPersonRole( $personId );

            $curyear = $this->Mahasamadhi_proxy->getEventYear();

            $data['title'] = 'Mahasamadhi Camp Attendee Report';
            
            if (in_array("board",$group) or in_array("mahasamadhi",$group) or in_array("admin",$role) or in_array("superadmin",$role))
            {
                $mrhinfoarr = $this->Reports_proxy->getMahasamadhiRegistrantsBadgeData($curyear);

                //echo('Number of registrants: '.count($mrhinfoarr));
                //die;
                
                $data['mrhinfoarr'] = $mrhinfoarr;
                $data['year'] = $curyear;
                $data['urlKey'] = $urlKey;
                $data['view'] = 'cmb/reports/mahasamadhi_attendee_report_view';
            }
            else
            {
                redirect( base_url() . 'cmb/member/login_home/true/' );
            }
            
            $this->load->view( self::$REGISTRATION_TEMPLATE, $data );
        }               

		public function mahasamadhi_dashboard_report( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/mahasamadhi/Mahasamadhi_proxy');
			$this->load->model('proxies/Reports_proxy');
			$this->load->library('encrypt');
			
			$is_logged_in = $this->session->userdata( 'is_logged_in' );
			if (!$is_logged_in)
			{
				redirect( base_url() . 'cmb/member/login_home/' );
			}

			//$seckey = $this->Person_proxy->getPrimaryPersonSecurityKey( $urlKey );			
			$seckey = $this->Person_proxy->getPersonSecurityKey( $this->session->userdata( 'person_id' ) );
			if ($seckey != $this->session->userdata( 'logged_in_key' ))
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			//$personId = $this->Person_proxy->getPrimaryPersonID( $urlKey );
			$personId = $this->session->userdata( 'person_id' );
			if ( $personId < 1 )
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$group = $this->Person_proxy->getPersonGroup( $personId );
			$role = $this->Person_proxy->getPersonRole( $personId );

			$curyear = $this->Mahasamadhi_proxy->getEventYear();

			$data['title'] = 'Mahasamadhi Management Dashboard Report';
			$data['curyear'] = $curyear;
			$data['urlKey'] = $urlKey;
			
			if (in_array("board",$group) or in_array("mahasamadhi",$group) or in_array("admin",$role) or in_array("superadmin",$role))
			{
				$reginfo = $this->Reports_proxy->getMahasamadhiDashboardData($curyear);
				
				$data['reginfo'] = $reginfo;
				$data['year'] = $curyear;
				$data['year'] = $curyear;
				$data['view'] = 'cmb/reports/mahasamadhi_dashboard_report_view';
			}
			else
			{
				redirect( base_url() . 'cmb/member/login_home/true/' );
			}
			
			$this->load->view( self::$REGISTRATION_TEMPLATE, $data );
		}				
	}
?>